Possible Duplicate:
Python: How do I pass a variable by reference?
How can I reassign a value to a variable that is passed as a function argument?
For instance, what I am looking to do is:
foo = True
def convert(foo):
if foo == True:
foo = 'on'
elif foo == False:
foo = 'off'
return foo
where foo
is now a string. The problem with the method above is that in order to change foo
from a boolean type to a string type the following must be passed:
foo = convert(foo)
whereas I am looking to do something like:
convert(foo)
or,
foo.convert()
Any ideas?