J
Joe Poniatowski
From what I've read in the tutorial and FAQ, I should be able to pass a
mutable object like a list as a function argument, and have the caller see
changes made to the list by the function. I must be doing something wrong -
the function in this case assigns items to the list, but in the main module
it's still empty:
Python 2.3.2 (#1, Oct 23 2003, 11:10:37)
[GCC 2.96 20000731 (Red Hat Linux 7.1 2.96-81)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
.... print l2
....
However, I can return the list and it works OK:
.... print l2
.... return l2
....
Am I missing something or just interpreting the documentation wrong?
Jp
mutable object like a list as a function argument, and have the caller see
changes made to the list by the function. I must be doing something wrong -
the function in this case assigns items to the list, but in the main module
it's still empty:
Python 2.3.2 (#1, Oct 23 2003, 11:10:37)
[GCC 2.96 20000731 (Red Hat Linux 7.1 2.96-81)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
.... l2 = ['word1','word2']ls = []
def f1(l2=[]):
.... print l2
....
f1(ls) ['word1', 'word2']
ls []
However, I can return the list and it works OK:
.... l2 = ['word1','word2']ls = []
def f1(l2=[]):
.... print l2
.... return l2
....
['word1', 'word2']ls = f1(ls) ['word1', 'word2']
ls
Am I missing something or just interpreting the documentation wrong?
Jp