Re:Where are we in the Python 3 transition?
by throwaway91919 on Friday January 01, 2016 @05:04PM
(#10823697)
Can you (or someone) clarify what problem you're talking about? This seems to work as expected for me:
Is it the fact that kwargs are required to have defaults? Or what?
[ Parent
| on HN ]
Re:Where are we in the Python 3 transition?
by saltylicorice on Friday January 01, 2016 @05:16PM
(#10823743)
The problem is that the default argument is mutable.
def f(a=[]):
a.append('v')
print a
f(['ok']) # ['ok', 'v']
f() # ['v']
f() # ['v', 'v']
Re:Where are we in the Python 3 transition?
by throwaway91919 on Friday January 01, 2016 @05:38PM
(#10823834)
Ah, thanks.
Re:Where are we in the Python 3 transition?
by raverbashing on Friday January 01, 2016 @05:13PM
(#10823730)
Nah, do it like this
def foo(i,x=[]):
x.append(i)
return x
foo(1)foo(2)
See what happens