469,352 Members | 1,653 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,352 developers. It's quick & easy.

Don't understand syntax error: unqualified exec is not allowed ..


I've syntax error which I totally don't understand:

########## mainfile :
import test_upframe2

if __name__ == '__main__':
var1 = 33
code = 'print var1 + 3 \n'
test_upframe2.Do_Something_In_Parent_NameSpace ( code )

########### file = test_upframe2 :
class Do_Something_In_Parent_NameSpace ( object ) :
def __init__ ( self, code ) :

def do_more ( ) :
nonvar = [3,4]
while len ( nonvar ) 0 : # <<<===
nonvar.pop() # <<<===

import sys
p_locals = sys._getframe(1).f_locals
p_globals = sys._getframe(1).f_globals
try :
exec ( code, p_globals, p_locals )
except :
print 'ERROR'
gives me:
SyntaxError: unqualified exec is not allowed in function '__init__' it
contains a nested function with free variables (gui_support.py, line

"unqualified exec" : I thought that meant there is some ambiguity in the
namespace, but I explictly definied the namespace

The function "do_more" is never called, so what does it matter what's
in there ?

If I remove the while-loop (which of course I can't) the syntax error

I can place the function either as a class method or as a normal
function outside the class,
which both works well.
But I want the method / function not to be hidden.

Why does the above syntax error appear ?
Are there other ways to hide the function ?

Stef Mientki
Oct 20 '08 #1
0 1457

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by kepes.krisztian | last post: by
6 posts views Thread by Ivan Shevanski | last post: by
1 post views Thread by Sandesh | last post: by
127 posts views Thread by bz800k | last post: by
2 posts views Thread by sva0008 | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.