How do I access all global variables inside a module (I don t who they are in advance)?
For example
file m.py:
def a(s): exec( print +s)
main code:
import m x=2 m.a( x*2 )
Sommaire |
How do I access all global variables inside a module (I don t who they are in advance)?
For example
file m.py:
def a(s): exec( print +s)
main code:
import m x=2 m.a( x*2 )
You want to use eval() here and not exec().
But what are you actually trying to do....the usage of eval() and exec() is in general bad style and in general not needed (especially scary when it comes to security considerations).
License : cc by-sa 3.0
http://stackoverflow.com/questions/13501464/access-global-variables-in-a-python-module