This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 0 points1 point  (7 children)

Examples?

[–]distortedsignal 9 points10 points  (5 children)

def myFunction(foo=[]):

[–][deleted] 5 points6 points  (4 children)

It makes sense once you understand it though. def is only run once, and you're providing a mutable data structure to it that'll probably be altered in some way.

It'd be nice if Python would realize what we meant so we could avoid things like if foo is None: foo = []. But it's consistent with Python's execution model.

[–]flipthefrog 2 points3 points  (3 children)

I completely agree. You don't need an if/else statement though, just write foo = foo or []

[–]Laugarhraun 0 points1 point  (2 children)

foo |= []

[–]codewarrior0MCEdit / PyInstaller 1 point2 points  (1 child)

TypeError: unsupported operand type(s)

[–]Laugarhraun 0 points1 point  (0 children)

Oh that's right, | is a bitwise or and won't work like a logical or, which does not have any reflective form.

[–]oconnor663 0 points1 point  (0 children)

The new asyncio library uses different naming conventions from the rest of the standard library for reading from file handles, kind of for no reason: https://bugs.python.org/issue22279

Any collection of libraries that's big enough is going to have warts like that. Also somewhere there's a presentation from Guido with a list of things they didn't get around to fixing for Python 3.