Gathering variable names from within a function.
Michele Simionato
mis6 at pitt.edu
Sat Jul 5 09:11:51 EDT 2003
"Xavier" <sabu at pure-elite.org> wrote in message news:<mailman.1057315927.28411.python-list at python.org>...
> Greetings,
>
> I was wondering if there was a way to get a list of all the variables which
> were executed/created/modified within a function?
>
> Here is a simple example that comes to my mind:
>
> def getVars(func):
> ...
> ...
> ...
>
> def modVar(arg, arg2):
>
> Var1 = arg
> Var2 = arg2
> Var3 = arg+arg2
> return Var3
>
> def main():
>
> print getVars(modVar('test', 'test2'))
>
> # end
>
> naturally, "Var1", "Var2" and "Var3" should be printed to the user. Any
> idea?
>
What about
def modVar(arg, arg2):
Var1 = arg
Var2 = arg2
Var3 = arg+arg2
print vars()
return Var3
modVar('test', 'test2')
=>
{'arg2': 'test2',
'arg': 'test',
'Var1': 'test',
'Var3': 'testtest2',
'Var2': 'test2'}
> -- Xavier
>
> oderint dum metuant
Michele
More information about the Python-list
mailing list