« first day (2523 days earlier)      last day (2417 days later) » 

1:09 AM
When you run virtualenv in python and use pip from within the folder does my PATHS pip run or does the local pip run?
 
 
4 hours later…
4:51 AM
cbg
 
5:13 AM
I love sushi
class Sushi:
name = ''
price = 0.0

def __init__(self, name, price):
self.name = name
self.price = price
Is this a good sushi class?
 
5:43 AM
Needs more wasabi
cbg @AnttiHaapala
 
@nobism no, because price is not an intrinsic to the sushi, unlike its name (though it might have several names)
@nobism also, sopython.com/wiki/…
which is on the sidebar as
@AndrasDeak starred without seeing
 
I create a csv file everyday and want to publish it as google spreadsheet. But I dont want a new file everyday, same file should be over-written everyday. So that the link to the file remains same and only contents get updated everyday
 
use the api
 
 
2 hours later…
7:19 AM
cbg-ning
 
dyslexic ecabbag
 
Silly question: What happens to an object if I lose all references to it?
 
@holdenweb <3 that
 
@nobism it will eventually be garbage collected - typically immediately in CPython, which counts references.
 
@holdenweb ok thanks
 
7:30 AM
other implementations may use different garbage collection, and the immediacy is not a requirement of the language
 
I gotcha
I was just wondering what the consequences are of something like: x = Object(), x = Object()
 
7:48 AM
cabbage collection
 
user image
3
@AnttiHaapala Are you having any trouble in relation to Nebula being more or less down?
 
@IljaEverilä nope?
 
Lucky you, then.
I'm not entirely sure what parts of them are suffering, but all our internal services running there are out.
 
@IljaEverilä what is nebula ?
 
A large service etc. provider in Finland.
Great timing and all. New service published yesterday, git and all out today. We won't be pushing any fixes anywhere :D
 
8:04 AM
I hadn't realised that @kevin would even kick a tomato
 
What is cool with SO is the international community. I've heard things I would never probably heard otherwise
 
@IljaEverilä nebula didn't want to sell us anything :D
like in refused to even provide an offer...
strange company
now I will make sure that no one will ever buy anything from them.
 
Not a bad mission statement.
 
 
2 hours later…
9:54 AM
Cabbage!
 
@poke \o
 
cbg
 
 
2 hours later…
11:43 AM
Hello I am Back After Like 8 weeks :D
 
11:55 AM
cabbage
 
stackoverflow.com/a/40281507 and stackoverflow.com/a/42381416 – these answers completely missed the point of the question…
 
You need more rep Andras :(
 
My Life is...... just sigh ARGGGHHH
or should I say return self.func(*ARGS!!!!!!!)
 
12:03 PM
If I had 1 rep for each time a question/answer/comment on the main site made me sigh, I'd have more rep than Jon Skeet.
 
12:17 PM
@poke I really do
my occasional answers keep going below the radar but I don't want to bump them :D
 
12:40 PM
In a recent question, the OP's problem could have been solved in one line by using place() instead of pack(). But I knew that place() is typically an antipattern, so I went about explaining a completely different design that didn't require it. I got 99% through the implementation when I realized that the result would look like dog doo if I didn't use place. So my answer is twenty lines longer than it needed to be.
If I get a second wind I'll try to insert a lecture about how, although I used place here, in your actual code you should really try to use pack, and I promise it won't look like dog doo once you actually add all the buttons and health bars and sprites to your GUI, provided you make good use of rowspan options, margins, and nested frames, cross my heart and hope to die
 
And then we all just agree that Tk is kind of a mess
 
monkey see, doggy doo
 
Yes, although I don't think OP would have fared better with any other framework
 
thank you, that will be all
 
Is there a good Python GUI framework though?
Other than scrapping that idea and going with a webserver instead to make a website?
(because that’s how I always ended up doing things)
 
12:45 PM
In the future, all GUIs will be implemented as web pages, including web browsers
 
The future is already here
Because that’s already what’s happening
Half of Firefox’ UI is written in HTML
100% of Firefox’ UI is written in JavaScript (always has been like that)
 
It will only count when they completely remove all dependencies on the OS' rendering engine :-P
 
*cough* Firefox OS *cough*
 
Haha, see, the joke is, if it's 100% html, then you'd need a browser to run your browser, which is pointless ["please laugh" sign lights up pitifully]
 
the technological singularity we deserve, not the technological singularity we need
 
12:50 PM
@Kevin MS let you do this as well with their UIs (I think)
 
A browser written in HTML is as ridiculous and clearly impossible as an implementation of Python written in Python. So. Very. Impossible.
 
@Kevin Sort of like how self-hosting programming languages work? Like Rust?
@Kevin PyPy
 
He might have been joking with that very point
 
Yes, that was the joke
 
Is it correct to say that every child class should call its parents' constructors?
 
12:55 PM
I think Liskov's Substitution Principle says yes.
 
I guess it isn't, because nobody ever does it when the parent class is object...
 
Probably a design smell if it doesn't, but its not really a rule, more of a guideline
PyCharm will complain if you don't
 
So technically we should be calling object.__init__() every time?
That completely borks multiple inheritance, doesn't it
 
Assuming that object.__init__ is a no-op, then LSP doesn't actually require you to call it in subclasses, since doing so wouldn't change any property of the subclass instance to make it more object-like
The rule of thumb I'm sketching out here looks something like "you only need to call the parent constructor if the constructor actually modifies the program state in an observable way. If you're not sure, err on the side of caution. And you can never be sure except when inheriting from object"
 
cabbage
 
1:05 PM
But if you call the parent constructor "just to be safe" and the parent doesn't have a constructor, you just broke multiple inheritance
 
I'm not really familiar enough with multiple inheritance that I can agree or disagree with that
 
@Kevin LSP is more like "if your List subclass has a method called add(), it should add something and not launch the warheads", isn't it?
 
class A:
    pass

class B(A):
    def __init__(self):
        super().__init__()
        self.b = 'b'

class C:
    def __init__(self, c):
        super().__init__()
        self.c = c

class BC(B, C):
    def __init__(self, c):
        super().__init__()
        super(A, self).__init__(c)

A() # works
B() # works
C(3) # works
BC(3) # error
If A had an __init__(self): pass, it'd work
So if I'm diagnosing this correctly, you always want to call super().__init__ unless that would end up calling object.__init__
Which further means that any class inheriting only from object should have a constructor that does nothing
 
Hmm, I didn't even know it was possible to use zero-argument super when you have more than one parent.
Time to read the documentation on super for the millionth time
 
Joe
Hi I have a question
how you say in english : I am a quick man in my choices
>> I mean another word for : quick man
any body knows
 
1:17 PM
"I am a decisive man"
 
Joe
not like that I mean
I mean it is a negative thing in my personality
I do thing quickly when I thing about something
 
@Kevin I believe super() creates a proxy to <current_class>.__mro__[1] so the MI gets handled thru the MRO
 
multiple parents or not doesn't matter for super. It gives you the class following after __class__ in type(self).__mro__, where __class__ is the class that you're using it in
 
@Joe perhaos you could say you are impulsive?
 
@Rawing - important distinction "where __class__ is the class that you're using it in" vs self.__class__
"I am a hasty man"
 
1:23 PM
as long as you have a call to super() in your function, python automagically sets the __class__ variable to the class in which the function is defined
 
In which namespace?
 
Hmm, why do I keep getting TypeError: __init__() missing 1 required positional argument: 'c' on B's init, then? Nowhere in B's inheritance hierarchy does the parameter c even exist
 
Ah, so super() is like super(__class__, self) since __class__ is defined to be the local class?
 
My working assumption was that the self in B.__init__ was still a BC instance, and for some reason calling super from within B caused C.__init__ to get called
Despite them being siblings
 
@PaulMcG yep.
 
1:27 PM
\o cbg
 
@davidism - Ever heard of secured transport? Ever heard of TLS and SSL? Shaking my head. — alvits 1 min ago
This person is advocating using pickle to send public data.
@alvits yes, but needlessly opening a security hole as big as pickle because you don't know what to do with a file object is insane, and not something that TLS can prevent exploitation of. — davidism 1 min ago
 
class A:
    pass

class B(A):
    def __init__(self):
        print("Calling super from within B.")
        super().__init__()
        print("Completed calling super from within B.")

class C:
    def __init__(self):
        print("C.__init__ is being called.")

class BC(B, C):
    def __init__(self):
        super().__init__()

BC()
#result:
#Calling super from within B.
#C.__init__ is being called.
#Completed calling super from within B.
How the heck does B call C
 
This is one of those times I'm tempted to say "hey, you might want to check who you're talking to."
 
That's because B and C share a common parent - object. Sibling class functions are called before parent class functions - C is inserted between B and object
>>> BC.__mro__
(<class '__main__.BC'>, <class '__main__.B'>, <class '__main__.A'>, <class '__main__.C'>, <class 'object'>)
 
I think pickle is appropriately named, since it would put you in a certain predicament when trying to use it in a securely manner.
 
1:30 PM
super calls sibling constructors? Why on earth is that desirable?
 
yam it, I'm just going to say it
@davidism - it sounds like you have no idea how TLS and SSL work. JSON is insecure as well, but why is it acceptable? TLS and SSL. — alvits 49 secs ago
 
I've been linked an hour-long video about that subject in the past, let me see if I can dig it up...
 
I still don't understand why BC's mro is relevant, though. I'm inside B.__init__, so I expect super() to return a proxy object that follow's B's mro. Not BC's mro.
 
And yet,
(Pdb) x
<super: <class 'B'>, <BC object>>
(Pdb) x.__init__
<bound method C.__init__ of <__main__.BC object at 0x01AFC7D0>>
 
1:33 PM
It's relevant because self is an instance of BC
super() operates on the mro of type(self)
 
@davidism <3
 
Then I don't understand why super even has a type argument if it's just going to throw it away and use the type of its object-or-type argument
 
@alvits "Warning The pickle module is not secure against erroneous or maliciously constructed data. Never unpickle data received from an untrusted or unauthenticated source." - the Pickle docs. Check out the Python docs if you aren't familiar with Python - they're designed to be unintimidating for beginners :-) — Robert Grant 41 secs ago
Got your back bro
 
Joe
thank you all for help,,, God bless you
 
It's basically like this:
def super(cls, inst):
    mro = type(inst).__mro__
    i = mro.index(cls)
    return mro[i+1]
 
1:37 PM
Lol, they just keep going.
 
it doesn't throw anything away
 
TIL: a class A inheriting from another class B can also specify what B inherits from (for its implementation)! Frickin magic.
 
Robert got ignored ;( seems like this person has a personal bone to pick with you, David :\
 
there is __reduce__() method to pickle accidental different recurrent type than the first one
 
I don't like the way it works either. It basically means that my class's inheritance tree is part of my class's public API, whether I like it or not
 
1:40 PM
@davidism “ah so you are referring to the module”, no, the vegetable… omfg.
 
I assume mro[i+1] is a simplification that glosses over what happens when the next class in the list doesn't have an implementation of the method you're looking for. Because BC's mro is (BC, B, A, C, object), so I'd expect super(B, self).__init__ to only call C.__init__ if there's logic that notices that A.__init__ doesn't exist and skips to the next element in the mro
 
incidentally, the question also needs to be closed
 
@Kevin Yeah, you're right about that.
 
Which brings us back to the beginning of the conversation: if A had defined an __init__, then it would get called like we want.
 
I’m btw. pretty sure that pickling a file handle is absolutely the wrong approach to transfer files… >_<
 
1:44 PM
I wonder if pickle was made as a proof of concept that made a wrong turn.
 
So to summarize:
1) always call `super().__init__`
2) if you're inheriting only from `object`, have a `def __init__(self): pass`
At least that's the cleanest way to deal with this yam I can think of.
 
Assuming "never use multiple inheritance" is off the table ;-)
 
Not using multiple inheritance is just people being scaredy cats.
 
Well, I don't like to prevent my child classes from doing anything... if they want to shoot themselves in the foot, let them :p
 
@Rawing So you’re a bad parent?
 
1:47 PM
No! It's a learning experience!
 
@Rawing I don't think item 2 is necessary
 
But without 2), then the BC constructor from chat.stackoverflow.com/transcript/message/39106948#39106948 crashes
 
You can choose between 2) or 3) Slap a big, fat, "not suitable for multiple inheritance" sticker on your class
Well, "not suitable" isn't correct I guess. Maybe more like "makes multiple inheritance more difficult than it needs to be"
 
My first instinct is to say "YAGNI, but if you really do need it some day, it's trivial to go back and add the __init__ boilerplate exactly when it becomes necessary to do so and no sooner", but my second instinct is "It's trivial iff you have write access to the class definitions, which might not be the case for people using an API that you have published. If they try to inherit from two classes in your module and it blows up, they'll curse your name for a thousand generations"
 
A thousand subclasses
 
1:59 PM
This is assuming that those users have no recourse whatsoever. I don't know if you can work around it by explicitly calling B.__init__(self); C.__init__(self, c) instead of using the convenient-if-not-broken super approach
 
Unless your code is designed for it, why would they be trying to inherit two of your classes? It's generally not useful to decide to subclass two arbitrary classes.
 
Having to write two additional lines of code is not thousand-generation-curse-worthy
 
This same argument came up a month ago, and I said the same thing: it's never a problem because you don't arbitrarily decide to use multiple inheritance on things that don't need it.
People are getting way too hung up on the theoretical cases.
 
Heck if I know. I've used multiple inheritance like twice in the last five years. Both times at least one of the classes was more of an Interface than an actual class
class Listenable:
    def __init__(self):
        self.listeners = []
    def register(self, listener):
        self.listeners.append(listener)
    def alert(self, msg):
        for func in self.listeners:
            func(msg)

class NoisyList(Listenable, list):
    def __init__(self):
        Listenable.__init__(self)
    def append(self, item):
        self.alert("item {} is being added to the list".format(item))
        list.append(self, item)

seq = NoisyList()
seq.register(print)
seq.append(23)
Something along those lines.
 
True, it's never been a problem in real code. I think this kind of stuff makes python's inheritance needlessly difficult to grok though.
 
2:04 PM
Does Python syntax use ~?
 
That's binary negation, IIRC.
Not terribly common unless you're doing some low level bit manipulation
 
Thanks!
 
@RomanLuštrik not one bit
 
Or, hmm, is it twos complement negation? It's some kind of negation.
 
Makes me wonder if it's a Pandas thing...
 
2:08 PM
:39108149
class parentclass(childclass, list):
....
parentclass.childattribute
that how it works ?
 
@RomanLuštrik can be overloaded for a class by implementing __neg__. I use it in pyparsing as an operator on parser expression objects, to mean "not followed by".
 
Welllll neg is for unary minus. invert is for tilde.
 
Bah! Yes, __invert__, not __neg__
Here was the syntax Roman was asking about: df_no_outliers = df[~(df.outlier)]
 
Had to double-check myself, since these dunders occasionally change names. I'm looking at you, __nonzero__/__bool__
 
Sounds like that ~ is turning True to False and vv.
 
2:12 PM
@Kevin I think outside of “hey look, I can do multiple inheritance to do fancy stuff” reasons, I only ever used it for mixing purposes, and those usually come without any constructor arguments
 
>>> ~True
-2
>>> ~False
-1
 
~ != not
 
Now I m completely confused :p
 
I would not be surprised if it was indeed overloaded by Pandas.
 
That seems very likely to me.
 
2:14 PM
~ is
 
Look:
97
A: How can I obtain the element-wise logical NOT of a pandas Series?

unutbuTo invert a boolean Series, use ~s: In [7]: s = pd.Series([True, True, False, True]) In [8]: ~s Out[8]: 0 False 1 False 2 True 3 False dtype: bool Using Python2.7, NumPy 1.8.0, Pandas 0.13.1: In [119]: s = pd.Series([True, True, False, True]*10000) In [10]: %timeit np.invert(...

 
by numpy
~Bool === logical_not(Bool)
 
That's settled dusts off hands.
 
Bool not to be confused with bool, I assume?
 
Stack Overflow, where you get advice to *pickle* a file object to serialize it in JSON. That's not secure? "Have you ever heard of TLS?" 😭
I need to turn more of the bizzare SO stuff into tweets.
 
2:18 PM
>>> int ( not 0 )
1
>>> int ( not 1 )
0
 
bool(x) === not not x
 
2:31 PM
>>> class YouWillHateThis:
        def __bool__ (self):
            return random.choice((True, False))
>>> x = YouWillHateThis()
>>> bool(x) == (not not x) # sometimes
False
 
cbg all
The US gov't saying "this isn't the time to talk about trends and climate change, but all those poor people affected" sounds like Experian saying "this isn't the time to talk about security, but all those poor customers"
 
*rolls eyes*
 
except that hurricanes have been happening for... millenia?
the amount of political grandstanding going on around that event is ridiculous to me
cbg
 
I'm getting annoyed at Equifax blaming Apache
 
no one takes responsibility for anything anymore
 
2:44 PM
@enderland that's not my fault!
 
cue Mask voice "It was ME"
 
yes it is. it's 100% your fault and you should feel bad. you probably caused Irma too
morning pondering, given apparently people were shooting at Irma to make it go away: could you detonate enough nuclear weapons to actually make a hurricane move away?
 
"Somebody stop me!"

I imagine if you throw enough force in the form of nuclear explosions, you could sufficiently disrupt the atmospheric/weather mechanisms enough that there's technically no more hurricane, but I feel like you'd prefer the hurricane?
 
For any Django experts out there... is there any reason the following shouldn't be done:

class Animal(models.Model):
    is_active = models.BooleanField(default=False)

    def make_active(self):
        self.is_active = True
        self.save()
 
@toonarmycaptain details details. I am only curious if you can actually cause it to move or something :P
would be a good XKCD whatif
 
3:18 PM
I mod flagged that whole "pickle is secure over TLS" comment chain and it's gone now. Much better.
 
\o/ my comment survived :D
 
Apparently the answer is "maybe" but you wouldn't want to. The issue is mostly scale - apparently a hurricane such as Irma releases the heat energy equivalent of a 10MT nuke...every 20 minutes. So, sure, you might be able to disrupt one with a nuke, but the size of nuke required would probably be prohibitive.
But "just push it away into the middle of the ocean" as opposed to dispersing it, I can't find anything
 
@toonarmycaptain do it over the ocean then! :P
 
General notice: Don't give @enderland nuclear weapons.
:p
 
@poke you weathered the storm and came out with pineapples.
 
3:25 PM
@enderland Apparently the NOAA did a pretty extensive article about this suggestion...but the page isn't loading for me. aoml.noaa.gov/hrd/tcfaq/C5c.html
 
> The entire human race in 2011 used about a third of the energy present in an average hurricane.
 
you can turn this enery into beneficial thing
 
rb folks
 
rbrb Andy \o
 
hmmm if clause with 3 elifs... time to reconsider this design...
 
3:35 PM
Time to PEP in a switch statement
 
lol
"hey guys I have a great idea, we can add a switch statement!"
 
switch expr:
    case literal_expr:
        pass
    case literal_expr:
        pass
Would kind of look nice
I guess
 
@RobertGrant I'm actually not really sure how to best refactor this, given that it's in an __exit__ condition on a contextdecorator which means either I leave a bunch of stuff like that, or, write multiple contextdecorators designed to handle each 1-off situation (which I'm not sure is better)
 
It'd be nice if it had sane defaults, i.e. it breaks unless you tell it not to
 
Meh, three elifs don't trigger my code smell detector.
 
3:37 PM
        e_to_raise = None
        if exc_type and self.failure_exception:
            e_to_raise = self.failure_exception
        elif exc_type and not self.failure_exception:
            e_to_raise = TimeoutError
        elif not exc_type and self.long_running_exception:
            e_to_raise = self.long_running_exception
        elif not exc_type and self.failure_exception and not self.long_running_exception:
            e_to_raise = self.failure_exception
        else:
            e_to_raise = TimeoutError
how about that?
 
You could cut out the last bit by starting with e_to_raise = TimeoutError
 
ah true
 
Sadly, that doesn't change the readability
 
e_to_raise = TimeoutError
if exc_type:
    if self.failure_exception:
        e_to_raise = self.failure_exception
elif self.long_running_exception:
    e_to_raise = self.long_running_exception
elif self.failure_exception:
    e_to_raise = self.failure_exception
Same thing
 
ah, I like that better (though now I'm at like 3 levels of nested ifs... but it's more readable I guess?)
 
3:40 PM
18 hours ago, by Idle001
hey does anyone have a clue how byteplay code works ?
 
e_to_raise = SomethingBadHappenedError, job's done
I don't know what byteplay code is, so no
 
You've had 18 hours to find out!
You just can't get the Kevins these days.
 
if exc_type:
    e_to_raise = self.failure_exception or TimeoutError
else:
    e_to_raise = self.long_running_exception or self.failure_exception or TimeoutError
Even…?
Need a unit test for that…
 
# see chat.stackoverflow.com/transcript/message/39109747#39109747 for documentation
e_to_raise = self.failure_exception or TimeoutError if exc_type else self.long_running_exception or self.failure_exception or TimeoutError
 
But that’s unreadable Robert…
 
3:42 PM
@RobertGrant oh gosh the python 1-liner of unreadableness! :D
 
module no veggies
 
Hmm, just spent thirty minutes installing a C# decompiler "JetBrains dotPeek". I clicked "complete installation", and... Nothing. No window, no README. No obviously new folders in Program Files.
 
I think I'm going to go with:
    e_to_raise = TimeoutError
    if exc_type:
        if self.failure_exception:
            e_to_raise = self.failure_exception
    else:
        if self.long_running_exception:
            e_to_raise = self.long_running_exception
        elif self.failure_exception and not self.long_running_exception:
            e_to_raise = self.failure_exception
 
@enderland if a: … elif not a: … is an anti-pattern.
 
Ah, here's a shortcut to it in the start menu, which I never look at for any reason.
 
3:43 PM
it's pretty readable and clean for the conditions, I think what @poke said would work but I don't really want to rely on precedence in the triple or clause
 
@Kevin you probably don't even want to use it with a dotfuscated product
 
Just get rid of the last and not, surely
 
It's this or nothing, though
I recognize the astronomically high chance of there being zero readable variable names
 
@poke doh. (embarrassed) hah
 
i'm just making sure no one else goes through same monthly pain i v gone
 
3:45 PM
@enderland and else: if a: too…
 
I guess if it matches the first if it'll early exit right?
 
That’s how if/elif/else structures work, yes.
elif is short for else if
 
ok. this is much cleaner now
    e_to_raise = TimeoutError
    if exc_type and self.failure_exception:
        e_to_raise = self.failure_exception
    else:
        if self.long_running_exception:
            e_to_raise = self.long_running_exception
        elif self.failure_exception:
            e_to_raise = self.failure_exception
 
Last elif is in a different place, although I'm not sure if that matters
 
3:49 PM
fajklsd. this is the sort of thing that makes me question whether I know anything about programming at all, lol
 
the answer is always "yes, but not enough"!
 
derp derp
Wanted to test the upload progress bar I built, so I uploaded a 100 MB file.
I forgot though that my test server is configured to print out the file contents.
So now I’m sitting here, waiting for the server to finish printing 100 MB of null bytes for it to become responsive again… >_<
Console IO is so terrible…
 
Have you looked at tqdm for progress bar?
 
DSM
Tuesday cabbage for all!
 
@poke technically, that first nested if could be if exc_type and self.failure_exception though but I guess that's still much better than what I was working on ;)
 

« first day (2523 days earlier)      last day (2417 days later) »