exec execution scope

Eric Texier erict at millfilm.co.uk
Wed May 22 10:08:09 EDT 2002


1I am sure it's a well known limitation of the "exec" command in python,
but does someone knows
a trick to make this work without defining the "helpFunct" in the global
space and without
using "rexec" since I need self to be ?visible?.



Thanks

class atask:
 ##################
        def __init__(self,name):
            self.NAME = name
            self.COMMNAND = """ """
        def printName(self):
            print self.NAME
        def execute(self):
            exec(self.COMMAND)

a = atask("myName")

a.COMMAND = \
"""\n
def toto(self):
    for i in range(3):
        self.printName()
        print i
    helpFunct()

def helpFunct():
    print "in Other"

toto(self)
"""
#print a.COMMAND
a.execute()




More information about the Python-list mailing list