« first day (2593 days earlier)      last day (2338 days later) » 
00:00 - 17:0017:00 - 00:00

5:00 PM
It's actually equivalent to (sensor in data.items) and (data.items() == sensor) and (sensor in fieldnames)
 
this is actually my issue
i dont understand what do you mean with:
It's actually equivalent to (sensor in data.items) and (data.items() == sensor) and (sensor in fieldnames)
@Kevin
 
That's how operator chaining works. a op b op c op d equals (a op b) and (b op c) and (c op d) where op is any operator, including == and in
The feature exists so you can do things like 0 < x < 100 but it often trips up users who use it for something other than comparing numbers
 
wim
IIRC in is not an operator
 
Rule of thumb: just because an expression looks like it makes sense in English, does not mean it does something sensible in Python
 
wim
though it does also chain with same precedence as comparison operators
@PM2Ring taking a look now ... (why me?)
when someone want a "class property" it usually mean they want a regular property on the metaclass
 
5:07 PM
@kevin what would you suggess to fix it ?
 
@DSM I think not long after I got edit privs, you were one of the friendlier people that noticed I'd accidently edited my answer into the question instead of editing my answer :p
 
wim
@JonClements hey Jon, take a look here - all accepted answers are self-accepts
 
@AhmyOhlin I have a suggestion for you, which I am composing now. I'll post a reply on the question in a minute.
 
wim
Is that something mods might drop the user a message about? There are better answers from other users on most of those.
 
@wim Nothing wrong in principle with that - if you can see an issue and there's just a large amount of non-sensical answers that qualify for NAA/VLQ then use those - or custom flag and detail what you can with some examples. I don't have time now to review it.
 
wim
5:18 PM
You don't think there's something wrong in principle? It kinda goes against the etiquette of the site.
I don't think the user is malicious, just clueless. He copy and pasted code from my answer and then posted his own answer with it.
Then I look in history and it's a repeating pattern here ...
 
No - self answering isn't wrong in principle... what's off is choosing your own answer that really isn't one - that can be handled by flagging the answer as NAA if applicable and then the community can review it and recommend it be deleted if so (the acceptance mark won't prevent that happening).
 
@wim Depends on how you define "operator". the in token is present under comp_operator in Python's EBNF syntax, along with the usual suspects of <, >, ==, etc.
 
However - if it's a long term - accepting your own (non) answers when other clearly better answers are available (more like just leaving yourself a note like "yeah... fixed it by rebooting the computer") then yes - do as I said - flag it with a couple of examples and your concern and it'll get reviewed.
I just personally don't have time right now to look at it - there's 24 other mods that can if you put it in the queue with the appropriate information expressing your concern.
 
@wim IIRC you know more about that stuff than I do. :)
 
(but a very very quick glance seems to indicate they need a message and some cleaning up of useless answers should happen - but it needs to be reviewed properly - that's all I'm saying @wim)
 
5:26 PM
Playing this on loop
The Prelude Op. 28, No. 15, by Frédéric Chopin, known as the "Raindrop" prelude, is one of the 24 Chopin preludes. Usually lasting between five and seven minutes, this is the longest of the preludes. The prelude is noted for its repeating A♭, which appears throughout the piece and sounds like raindrops to many listeners. == Composition == Some, though not all, of Op. 28 was written during Chopin and George Sand's stay at a monastery in Valldemossa, Majorca in 1838. In her Histoire de ma vie, Sand related how one evening she and her son Maurice, returning from Palma in a terrible rainstorm, found...
 
@wim I saw one a bit like that the other day: 19 questions, 5 answers, with 4 of those answers self-accepts, but to be fair he'd also accepted answers from other people on most of his other questions.
 
@AhmyOhlin Ok, I posted a reply. Thank you for patiently complying with my requests for more information :-) Most people give up after fifteen minutes.
 
@Kevin thank you for your reply and your bonus as well. that is pretty cool
 
wim
@Kevin that might be changing soon
I also have an open bpo about it
 
i try to understand your suggestion
i replace my error with your suggestion . it doesnt work because python program dont join the if statement and this why python doesnt execute the rest-
So i will skip to the bonus
it may do the job :)
 
5:37 PM
You may be replacing the wrong thing. There shouldn't be an if statement anywhere near that loop.
 
@Kevin
 
#check first line of  fieldnames
with open(filename,'r') as myFile:
    reader = csv.DictReader(myFile)
    fieldnames = reader.fieldnames
    print(len(fieldnames), fieldnames)
    myFile.close()

#Compare the values with their  keys (fieldnames)
with open(filename,'a') as outfile:
    writer = csv.DictWriter(outfile, fieldnames)
    row = {}
    for fieldname in fieldnames:
        row[fieldname] = data.get(fieldname, "n/a")
    row["Time "] = Time
    writer.writerow(row)
No ifs.
 
DSM
@Kevin: minor, but if OP is using python 3 you'll want a newline='' added to your open.
 
Anyone looking for a junior level position? My company is hiring. Check it out at accendero.com/#careers
 
wim
It's just kind of sad to see stuff like this ... other members have spent good time to write a good quality answer with diagrams and everything and they don't get acknowledged (my upvote is the only one there)
 
5:38 PM
@wim Yeah it's pretty goofy as-is so I won't shed many tears if they change it.
@DSM I was wondering if there was anything I could do about that extra newline. Cheers.
Not sure which version of Python that OP is using, so I'll make a note in a postscript
 
DSM
You're in excellent company-- I once had to correct a Name on the same thing. :-) In 2 you want binary mode and in 3 you want newline='', so I'd say about half of the opens used with the csv module in Python on SO are technically wrong.
 
i copypasted your code yhich you posted here and i works well. i tested your code by changing the order of the sensorsvalues and i rexecuted the code. the result is that the Order of values is not change it. Thank you so much @Kevin. You are a python-brain. i will confirm your solution as correct. and i hope that i can make your soulution work after the implementations
 
Best of luck :-)
 
There are tons of old CSV answers that are written for Python 2, but which don't open the files in binary mode, so they only work correctly by accident. ;)
 
5:52 PM
Reminds me of the gun-o-tron that Python is represented as in i.stack.imgur.com/E0Qbo.png
 
@kevin
could your please explain me why you implement n/a in this line
row[fieldname] = data.get(fieldname, "n/a")
 
The get method of a dictionary may take one or two arguments. If the second argument is supplied, that is the value that will be provided if the key does not exist in the dict. Example:
>>> d = {1:2}
>>> d.get(1, 99)
2
>>> d.get(23, 99)
99
 
with this line you compare fieldname and values to get the right value. right ?
so what does n/a mean
 
In your code, "n/a" is the value that is inserted into the row if the data doesn't have any value for that column.
 
wim
I always wished for get to be lazy
 
6:02 PM
that means when get mothod doesnt find the argument so it will write automatically n/a ?
 
In other words, it's a shorter way of writing
    for fieldname in fieldnames:
        if fieldname in data:
            row[fieldname] = data[fieldname]
        else:
            row[fieldname] = "n/a"
 
wim
i.e. to be more like: d[k] if k in d else other
so that other can be a function call or something else you don't want evaluated
 
@AhmyOhlin Yeah.
 
wim
ugh, just got punk'd by this :
 
this the version which i had before.
thanks (Y)
 
wim
6:03 PM
>>> t = ('my_tuple',)
>>> [v] = t
>>> [v] == t
False
 
@wim That would be wonderful.
 
DSM
@wim: there's a lot of stuff I wish were lazy in Python, but to be honest by the time I start imagining fixing it in a coherent fashion I wind up with a different and much better language. :-/
 
I remember a room regular using x, = ... for some terribly clever solution to a pointless riddle I posed, a couple weeks back.
I want to say it was "assign [[...]] to a variable in only one line"
But I'm pretty hazy on that
 
I find it really easy to misread one item tuples when they don't have parentheses. OTOH, that should be a style issue, definitely not a syntax issue.
 
@MartijnPieters I'm still using inoreader on your recommendation. Just renewed my subscription until Nov 2019 with their Black Friday deal.
 
6:10 PM
Sadly, chat search doesn't seem to accept a query like , = so I can't easily find the original context
 
@davidism cool!
 
Feeling pretty rustled that googling ",=" site:https://chat.stackoverflow.com/transcript/6 gives me a bunch of pages that don't have ,= in them
 
too broad / unclear stackoverflow.com/questions/47419894/python-simple-text-game I hate pointless YouTube so-called tutorials...
 
Where's that "verbatim" button that someone showed me the other month...
Now I'm searching the transcript for hints on searching the transcript
 
Cbg All
 
6:15 PM
Sep 28 at 17:39, by Andras Deak
tools -> click "all results", change to "verbatim"
No change :-I time to give up.
 
wim
>>> {0} == {0:0}.keys()
True
>>> {0} == {0:0}.values()
False
>>> [0] == {0:0}.values()
False
 
Curious.
 
@wim In Python 3, those methods return Views. The .keys View is guaranteed to be set-like, but that guarantee can't be made for .values.
 
>>> [0] == list({0:0}.values())
 
DSM
@PM2Ring: missing negative correct number of negatives there, I think..
 
6:27 PM
Also
>>> {(0,0)} == {0:0}.items()
True
 
I see. It would be bad if {0:0, 1:0}.values() returned a collection of length one.
Still leaves the question of "why not make the values list-like?"
 
@DSM It's pre-dawn typo time. :)
 
DSM
I wasn't even thinking of duplicate values, I was thinking of non-hashable ones.
 
@DSM Indeed.
 
ofc they couldn't be list-like back when dicts were unordered. But it's a new era.
 
6:30 PM
Ordered dicts are still at "implementation detail" status, are they not
 
@Kevin Well, it's better than a list because it's dynamic. The Views are really just an alternative interface into the dict object, so there's zero cost to them getting updated if the underlying dict changes.
 
I thought they were beyond "implementation detail" in the most recent version, but I have 0 citations for that fact
 
DSM
kwarg order is the only thing that's been stapled, IIRC.
 
If you made values views list-like, people would expect efficient indexing.
 
Hmm, point.
 
6:33 PM
@user2357112 True, but that shouldn't be too expensive with the new ordered dict. Should it?
 
I think even with orderliness you get O(N) indexing time in the worst case
 
The new implementation still has dummy entries, so you can't just jump to the right entry given its index.
 
Oh, ok. I can't remember the implementation details. I guess it uses a C linked list, which is O(n). But it's O(n) at C speed. :)
@user2357112 Ah, of course.
 
O(N-C) :-P
 
wim
It's subtle - the items is almost set like, because unique keys guarantees unique items
you can even make the items from non-hashable values:
>>> {'a':[]}.items()
dict_items([('a', [])])
and then you get runtime TypeError if you try to use it with a set operator
 
6:46 PM
They're set-like if the values are hashable, sort of like how tuples are hashable if the elements are hashable.
 
>>> a = {(1, 'a'), (2, 'b')}
>>> d = dict(enumerate('abcde',1))
>>> a.issubset(d.items())
True
>>> a < d.items()
True
 
@Kevin @PM2Ring Thanks for helping me out earlier guys. I have solved the problem by disabling pylint in VS Code and actually enabling the pep8 linter. That one seems a little more smart
 
wim
I wonder if they use the hash of the keys for the dict_items "set"
because taking the hash of the tuples could be very costly (since it implies hashing all the values too)
 
wim ought to get credit for his gordian-knot-cutting solution of "just don't use that tool"
 
wim
are you talking about that pylint question?
 
6:58 PM
@wim I think so, since that way you guarantee that the orderings of .keys, .values and .items are mutually consistent, which they're guaranteed to be, as long as you don't mutate the dict in between calls.
 
Yeah.
 
wim
Crazy stuff. I quite like the dict views, they have been very carefully implemented.
 
7:11 PM
Cabbage
 
Coworkers are talking. One says "I can't believe how difficult it is--" and I think "same" before he even finishes the sentence.
 
Does anyone know where I can get personal interview tutoring? For those tough algo and data structure questions?
 
I'm pretty sure you can hire someone to help you do that...
 
Hey! anyone aware of an online Python interpreter that is able to display images generated with PIL (e.g., this example: en.wikibooks.org/wiki/Python_Imaging_Library/Editing_Pixels)
 
@vaultah self-deleted
 
Nope. I detect a business opportunity.
 
7:46 PM
@moooeeeep There are some online REPLs that support tkinter, so if you're willing to write some code that puts your PIL image into a tkinter gui, you can use those.
 
DSM
@Johnston: not sure, but some of the code mentoring services -- the ones with the virtual interviews -- would probably be happy to help. I don't know how much they charge, though.
 
@DSM Thanks!
 
8:04 PM
@Rawing you mean repl.it ?
 
Yes
...Never mind, that's turtle.
 
I was also thinking about whether Jupyter would also be able to do that (most likely) but then again, with 5 minutes googling, I didn't find a hoster that enables anyone to do this online
 
wim
Is there any good question about the difference between data descriptors and non-data descriptors?
Specifically, the precedence of attribute lookup in instance __dict__ and why it's designed that way
 
@wim I assume, this is not what you are looking for: stackoverflow.com/questions/13007179/… , right?
 
There's also this
 
8:14 PM
@Rawing Well, turtle runs on top of tkinter. OTOH, just because they have tkinter, doesn't mean they also have PIL.
 
@moooeeeep Sorry 'bout that, I don't actually know any online interpreters that can do that. My brain was like turtle == tkinter :/
It also doesn't mean that they let you control tkinter, even if they have it because turtle needs it
 
@Rawing No problem! I already found another way to share my code and the output image (good old github) :]
 
wim
@moooeeeep good one, thanks!
added into my answer here stackoverflow.com/a/47421991/674039
 
8:32 PM
@PM2Ring Pyminifier is not very good at obfuscating code with foreign letters. It screws everything up.
 
Anyone try to do something like this?
0
Q: How to instantiate a new property object for each new parent object?

KronoSI'm working a special situation where I'm trying to emulate the django feel of model classes like so: class packet(models.packet): field1 = models.IntField() field2 = models.IntField() There's a lot of background interfacing using metaclassing but the over idea is to allow the user to ...

 
I was going to write an answer to that, then realized there's half a dozen different ways to implement the descriptors
 
@Rawing I'll take any solution at this point
 
I'll try to hack something together real quick
 
8:56 PM
@KronoS Your requirements actually require the code to be pretty hackish. You want the attribute to be an instance of IntField, but also behave like an int
 
That was the hope yes
I'm thinking similar to what Django does
 
I've only implemented the comparison __eq__, you'll have to implement all the other dunder methods as well to make it work like an int
 
@wim non_data_descriptor got over written because you didn't overwrite the __set__ function for it? if so, is that what it's called? TIL
 
@KronoS: Are you sure Django actually works like that?
 
no
lol
I'm going through your pastebin and I think we're onto something with the copy
I was orginally trying to use copy.deepcopy() but that wasn't actually copying anything
 
9:05 PM
That would be very odd, because that's literally its only purpose
 
only problem is that type(self)(**self.__dict__) doesn't seem to be working correctly
geting more vars that expected for init
@Rawing I thought so too, but when I tried to it was simply copying references to the same object
not an actual duplicate of the class
 
Why do you even want isinstance(p.field1, models.IntField)?
 
The copy method passes all attributes of the instance as arguments to the constructor, so if you add any attribute, you have to add the corresponding constructor parameter as well
Or rewrite the copy method
 
wim
@MooingRawr I don't follow ...
 
essentially I want the field to be able to do something like this:

p.field1 = 12
p.field1.to_bytes() #or other custom functions to the field itself
I check to make sure that's correctly done by checking that isinstance(p.field1, models.IntField) is True
 
wim
9:10 PM
You will have these:
 
@wim nvm was just trying to figure out your answer .... realized what you were doing... ended up not knowing what the name of what you were doing was, until I read your answer
 
wim
isinstance(type(p).field1, models.IntField)
isinstance(p.field1, int)
you can't easily have custom attributes on the actual integer returned because it's tricky to monkeypatch built in types
 
agreed
but I can customize __eq__ to check for a value
while still returning the object using __get__
thereby creating my own custom "IntObject"
maybe this will help to visualize what I'm dealing with:
you can see that p1 and p2's int_field are pointing to the same object as simple_pkt
b/c I set an internal val within the IntField class and this object is shared everywhere that val gets written over when the second packet's field is gotten
 
because you have class attributes rather than instance attributes
 
exactly!
 
9:20 PM
I didn't read the rest, just the picture
 
I'm trying to figure out how to make them instance attributes
@AndrasDeak that's fine
@Rawing I updated your copy function to something more like this:
def copy(self):
        return type(self.__class__.__name__, (Field,), copy.deepcopy(self.__dict__))
 
wim
don't assert with is btw you are relying on impl detail like that
 
and in my __init__:
for field_name in self.fields_order:
            self.__dict__[field_name] = self.__class__.__dict__[field_name].copy()
but even with that copy I'm still getting the same object!
@wim why not? I'm specifically trying to check that the two objects are not the same object in memory
 
wim
what's the point? if they're different objects then that's given
 
If I had an absolute business requirement to support p.field1.to_bytes(), I'd separate the IntField class and whatever class I used for p.field1. The responsibilities are completely different; they don't make sense as the same class.
p.field1 would resolve to an instance of an actual subclass of int with a to_bytes method on it.
 
9:28 PM
that was a quick off the fly example
one more concrete example would be that p.field1 is actually another packet
and therefore I would want it to return that packet so that I could go:
p.field1.field2
 
I'd still separate the classes. PacketField and whatever class models actual packets shouldn't be the same class.
 
do you have an example I could use?
I'm all for learning from my mistakes if that is indeed the case here
 
who wants to hear about how I blew my chance to a good internship
nobody is an acceptable answer
 
I'm using str.format to produce a report. One of the inputs to the report is a list. I'm to produce a line on the report for every element in the list. The length of the list is variable. Below is how I've done it. I'm asking if there is a cleaner way to do it that I'm missing. Also, does it change the answer if what I'm actually doing is writing sql and each line is an insert statement?
line_format = 'This is the line for {}'.format
lines_format = lambda lines: '\n'.join(map(line_format, lines))
repr_format = """This is a multi-line thing

I'll drop severl lines formatted using `line_format`
vvvvvvv  **here**  vvvvvvv
{formatted_lines}

And some additional stuff here: {another_thing}
""".format

print(repr_format(formatted_lines=lines_format(['a', 1, 'hello']), another_thing='World!'))

This is a multi-line thing

I'll drop severl lines formatted using `line_format`
vvvvvvv  **here**  vvvvvvv
 
...hey, wait, int already has a to_bytes. If you want your to_bytes to do something else, you may want to pick another name.
 
9:39 PM
to_bytes was a terrible example. I'm just saying I want to enable the ability to have custom methods and properties on the IntField class
or more general to a generic Field class that all other fields will inherit from
 
Anyway, an example might look vaguely like this.
 
@piRSquared have you considered using a template engine?
 
No.... should googling "template engine" do the trick? Doing that now
 
@user2357112 hmmmm Interesting. That would mean that I would need to keep track of basically another field type for each new field created
and actually I kinda already do this
 
Anyone know what the frame.__init__() does in tkinter?
 
9:47 PM
@user43850 You should never call __init__() directly. It is called whenever you instantiate an instance of a class, for example f = frame().
 
I understand that - I saw an example in a book/document somewhere that called frame.__init__().
I thought I was missing something
 
Probably in a subclass's __init__.
 
you can't trust what you find in books these days
internet is way more trustworthy
 
Do all subclasses have an __init__()?
Or just in tkinter
 
in general yes... there are exceptions though
 
9:50 PM
Most classes have __init__(), not just subclasses.
It is the python equivalent of a constructor, if you are familiar with that concept from C++, C#, or Java.
 
So, in a tkinter program, why am I creating __init__() classes to build a window?
 
Are you subclassing frame?
 
Give me a second, I'll see if I can find the example
My example seems to have wandered off. Thanks for the help!
 
@vaultah jinja2 will do. Thank you!
 
:)
 
9:58 PM
@Code-Apprentice It's pretty common to see stuff like Frame.__init__ calls in Tkinter instead of using super.
 
19 hours ago, by cᴏʟᴅsᴘᴇᴇᴅ
Need some advice. Here's a question: https://stackoverflow.com/questions/4477850/python-and-or-operators-return-value

And here's another question closed as a duplicate of the first: https://stackoverflow.com/q/47007680/4909087

I want to switch the dupe targets. Yay or nay?
 
And all classes have an __init__, if they don't define their own they inherit their parent's.
 
If nay, reason please.
 
-0.2, sets bad precedent
People answer blatant dupes, get upvotes, then the newer question becomes the canonical dupe target because "answers"
 
I want to do some side projects and was wondering if anyone needed some help?
 
10:04 PM
@cᴏʟᴅsᴘᴇᴇᴅ I'll look later when I'm not on my phone, and when I'm actually awake. :)
 
Come to think of it, -0.8
 
I'm also a little biased because I wrote a tutorial answer on the topic a couple of years ago.
 
-1 not because of which is answered later, but because I think the earlier one is a better dupe target.
Could be better with a little editing, though.
 
I suppose I could migrate my answer to a more popular question and hammer the one I originally answered, but then my answer would lose its current score and would be at the bottom of the pile.
 
@vaultah Granted, that shouldn't be happening, but it does happen more often than not. In fact, that is the fate of many hot network questions (from python at least)
 
10:18 PM
 
I might agree with user2357112's point, too, though, I just haven't read any of the answers to the newer question.
They look unnecessarily long-winded
 
Hah, you could say that of almost every canonical answer
 
wim
anyone know what that crazy directory structure in the pip wheel cache is all about? (~/.cache/pip/wheels/)
 
@PM2Ring it looks good actually. I think you'll get to the same vote count quickly if you repost it under the canonical question
wink
 
I don't read long questions like that I generally skip them.
 
wim
10:28 PM
^ this
 
... and you won't lose the reputation from that answer, even if you delete it @PM2Ring
 
wim
@PM2Ring I noticed your answers in general are way too long-winded. You should work on your conciseness
 
What? How does that work?
 
rep gets stuck after 60 days on upvoted posts
 
wim
Especially for canonical questions, distill it down to the essence and the most important details, no need to enumerate every single case
 
10:30 PM
+3 and above I think
 
@cᴏʟᴅsᴘᴇᴇᴅ what Andras said. It's explained here
 
@PM2Ring That's your answer??? I thought it was part of the question.
Well you answer it in depth I suppose. : /
 
@vaultah Hmm. I'll think about it.
 
So that's 2.8 nays
 
@wim Well, I like to be thorough. :)
 
10:36 PM
No kidding?
 
wim
It's possible to be thorough without being repetitive
 
If you hate long winded answers, see e-satis' CWs
 
There is a time and place for longer answers. I usually get the time xor place!
 
I suppose so, although I was intentionally a bit repetitive there because it's a tutorial, and because I wanted to hammer home the similarities and differences between and and or.
 
and that one is hardly too long
who can't read it through has it coming anyway
 
10:46 PM
Also, the perceived length of a post can be mitigated with good formatting. Visually break up components to help with flow of what's trying to be communicated.
 
Headers are a good way of structuring otherwise chaotic answers
 
wim
I think e-satis answers are great, they're long and thorough but they're well written
 
My eyes glaze over when I can't see the end of a thought and I think to myself, "oh crap, I don't have the attention span to digest that really long single thought"
 
And ----- line breaks.
 
wim
It's the difference between a 3 hours movie that has you gripped, and a 3 hours movie that badly needs an editor to remove repetitiveness that the director didn't have the heart to cut ..
 
10:50 PM
I like that analogy
 
Never thought about it like that. Meanwhile, some prefer the low budget 20 minute episodes that offer higher returns
 
Yes, Tbh, a lot of pandas questions are like that.
 
wim
heh, I just used a trick I learned from last year's AoC in production code
 
Just remembered that I have to wait for the 2017 site to be live before making the board
what trick?
 
11:07 PM
@MarcusAndrews the leaderboards from the previous years should still be usable
 
wim
that deque trick
that one where you do

queue = deque([root])
while queue:
    node = queue.popleft()
    queue.extend([X(parent=node) for x in node.children])
the one that was a sledgehammer for like half the questions in AoC 2017
 
or the BFS stuff?
*oh
 
wim
yep
 
@vaultah I think the old boards are by-year -- either way I'm using a new account / name so I wanted to start a new one
 
wim
I won't be able to play this year. Travelling all Dec
 
11:11 PM
I'm going to try to get a few in once in a while
Won't be able to do every night
 
11:53 PM
Can anyone explain why this or statement is not changing the " or ] but the whole string?
 
Yep that's it thanks.
 
00:00 - 17:0017:00 - 00:00

« first day (2593 days earlier)      last day (2338 days later) »