E
Elliot Temple
I want to write a function, foo, so the following works:
def main():
n = 4
foo(n)
print n
#it prints 7
if foo needs to take different arguments, that'd be alright.
Is this possible?
I already tried this (below), which doesn't work. foo only changes
the global n.
n = 3
def main():
def foo(var, context, c2):
exec var + " = 7" in context, c2
n = 4
foo("n", locals(), globals())
print n
if __name__ == '__main__': main()
print n
And of course I tried:
.... n += 3
....4
-- Elliot Temple
http://www.curi.us/
def main():
n = 4
foo(n)
print n
#it prints 7
if foo needs to take different arguments, that'd be alright.
Is this possible?
I already tried this (below), which doesn't work. foo only changes
the global n.
n = 3
def main():
def foo(var, context, c2):
exec var + " = 7" in context, c2
n = 4
foo("n", locals(), globals())
print n
if __name__ == '__main__': main()
print n
And of course I tried:
.... n += 3
....4
-- Elliot Temple
http://www.curi.us/