My application has a button to execute a python script dynamically using execfile. If I define a function inside the script (eg. spam()) and try to use that function inside another function (eg. eggs()), I get this error:
NameError: global name 'spam' is not defined
What is the correct way to call the spam() function from within eggs()?
#mainprogram.py
class mainprogram():
def runme(self):
execfile("myscript.py")
>>> this = mainprogram()
>>> this.runme()
# myscript.py
def spam():
print "spam"
def eggs():
spam()
eggs()
Also, I can't seem to be able to execute a method from my main application in the script. i.e.
#mainprogram.py
class mainprogram():
def on_cmdRunScript_mouseClick( self, event ):
execfile("my2ndscript.py")
def bleh():
print "bleh"
#my2ndscript.py
bleh()
The error is:
NameError: name 'bleh' is not defined
What is the correct way to call bleh() from my2ndscript.py?
EDIT: Updated first issue