Repost: execfile() confusion

Petr Kubanek petr at kubanek.net
Fri Sep 28 21:52:44 CEST 2001


What's happen, if you use global in test2.py?

x is local to test2.py. 

Another possibility is to use __main__ module. But these is now depreciated.

> ##############
> #### test2.py ####

global x

> x = 'spam'
> 
> #### test.py ####
> def doit():
>     execfile( 'test2.py' ) # x = 'spam'

      global x

>     print x
>     
> doit()
> ##############




More information about the Python-list mailing list