Python function argument scope (Dictionaries v. Strings)
- by Shaun Meyer
Hello, given:
foo = "foo"
def bar(foo):
foo = "bar"
bar(foo)
print foo
# foo is still "foo"...
foo = {'foo':"foo"}
def bar(foo):
foo['foo'] = "bar"
bar(foo)
print foo['foo']
# foo['foo'] is now "bar"?
I have a function that has been inadvertently over-writing my function parameters when I pass a dictionary. Is there a clean way to declare my parameters as constant or am I stuck making a copy of the dictionary within the function?
Thanks!