Problem using exec function & classes
news python
fabella at free.fr
Thu Nov 29 12:15:58 EST 2001
if you execute this exemples:
#----------------------
def test1():
class c1:
global n1,n2
global verify1
verify1=c1()
>> test1()
>>verify1
<__main__.c1 instance at 0106D2B4>
*****************
* verify is now global *
*****************
but doing this similar exemple ----------->
#----------------------
def test2():
exec("class c2:\n global n1,n2")
exec("global verify2")
exec("verify2=c2()")
>> test2()
>>verify2
NameError: name 'verify2' is not defined
is somebody have any idea why "exec" instruction don't do the same thing,
and how to correct this problem, please let me know
Thank's
François Abella -- Qualicontrol --
More information about the Python-list
mailing list