3 ms·
This can be fixed by one of my favorite Python oddities, True = False This is right up there with default arg instances getting cached across calls, though it
by echelon 7y ago
This can be fixed by one of my favorite Python oddities,
True = False
This is right up there with default arg instances getting cached across calls, though it's perhaps better suited for an underhanded Python competition.
Have fun with it. Redefine it to be true 90% of the time.
- 1337shadow 7y agoYou'll need to find another one, the above results in SyntaxError: cannot assign to True
- echelon 7y agoI could have sworn that was still a thing in Python 3, but it looks like they've formally been keywords since 3.0. I suppose it took awhile for the default Python shipped with systems to be 3.*, because I show people this anytime Gary Bernhardt's "wat" talk is brought up. Edit : Here's some of the fun from Python 2.X not treating True and False as keywords: https://stackoverflow.com/questions/13665989/in-python-how-to-recover-from-joke-statements-like-true-false https://stackoverflow.com/questions/13665989/in-python-how-t...
- njharman 7y ago> default arg instances getting cached across calls That is not what is happening at all, logically or semantically. Effectively this is. # People not understanding when the # function definition including arguments is evaluated. mutable_instance = list() def func(change_me=mutable_instance): pass
- pansa2 7y agoWouldn’t something like this have been better? def func(change_me=None): if change_me is None: change_me = list() ...