Why I need to declare import as global in function
didier.doussaud at gmail.com
didier.doussaud at gmail.com
Wed Nov 30 03:42:57 EST 2005
I think I understand my problem, but first the sample code extracted to
my project.
Rq : it's an automatic run of unitary test, the names of unitary test
are parameter of main program "imported" file via the "execfile"
function (an usage of "import" instead may be a solution....) :
file run.py :
----------------
def run_ut( test ) :
# to have the problem the execfile MUST be in a function
execfile( test )
run_ut( "ut_00.py" )
file ut_00.py :
--------------------
import math
def f() :
## global math # <-- just decomment this line to avoid error
print "Second access :"
print "\t",math.pi # ERROR
print "First access :"
print "\t",math.pi # OK
f()
More information about the Python-list
mailing list