Problem using exec function & classes

Kragen Sitaker kragen at pobox.com
Thu Nov 29 20:07:46 CET 2001


"news python" <fabella at free.fr> writes:
> 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

You need exec("global verify2; verify2=c2()") or
exec("global verify2\nverify2=c2").  HTH.




More information about the Python-list mailing list