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

Discussion in 'Python' started by Stef Mientki, Oct 20, 2008.

  1. Stef Mientki

    Stef Mientki Guest

    hello,

    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
    408)

    "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
    disappears.

    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 ?

    thanks,
    Stef Mientki
     
    Stef Mientki, Oct 20, 2008
    #1
    1. Advertisements

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. j vickroy
    Replies:
    1
    Views:
    1,439
    j vickroy
    Oct 8, 2003
  2. Replies:
    3
    Views:
    617
  3. Chris Saunders

    Don't understand syntax error

    Chris Saunders, May 16, 2005, in forum: C Programming
    Replies:
    9
    Views:
    739
    CBFalconer
    May 17, 2005
  4. Antoon Pardon

    I don't understand this syntax error

    Antoon Pardon, Jan 19, 2009, in forum: Python
    Replies:
    1
    Views:
    388
    Peter Otten
    Jan 19, 2009
  5. Good Night Moon
    Replies:
    9
    Views:
    543
    Rick DeNatale
    Jul 25, 2007
  6. Albert Schlef

    Syntax error I don't understand

    Albert Schlef, Dec 28, 2008, in forum: Ruby
    Replies:
    9
    Views:
    363
    Brian Candler
    Dec 28, 2008
  7. Iñaki Baz Castillo
    Replies:
    13
    Views:
    785
    Iñaki Baz Castillo
    May 1, 2011
  8. Larry

    Don't understand this syntax -

    Larry, Feb 16, 2005, in forum: Perl Misc
    Replies:
    8
    Views:
    345
    John W. Krahn
    Feb 17, 2005
Loading...