Access global variables in a python module

De openkb
Aller à : Navigation, rechercher

Sommaire

Questions

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 )

Answers

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).

Source

License : cc by-sa 3.0

http://stackoverflow.com/questions/13501464/access-global-variables-in-a-python-module

Related

Outils personnels
Espaces de noms

Variantes
Actions
Navigation
Outils