First of all,
class WindowsBalloonTip:
should be
class WindowsBalloonTip(object):
because the former is an old style class, which has disappeared in Python 3 and is in recent versions of Python 2.x only for backwards compatibility.
Ethan's answer is correct, but probably unclear to you if you're asking this question. A full explanation is here.
When ballon_tip()
is run, it first searches the local namespace -- balloon_tip()
's namespace -- for something called WindowsBalloonTip
. When it can't find it, it searches the global namespace. Since you didn't provide anything to the globals
parameter to execfile()
, it defaults to the namespace of callscripts()
, which doesn't have anything named WindowsBaloonTip
inside of it, and errors.
To fix this, you can pass globals()
as an argument to execfile
, but this will pollute the global namespace of your main script, which you probably don't want. You can also declare everything inside of secondary.py to be global, but you probably don't want to do that since the whole point is to test secondary.py.
The issue is execfile
. execfile
is an ugly, hack-y way to do things. import
is better. One solution would be to write something like this inside secondary.py:
def test_harness():
balloon_tip("test test", "Running")
hi()
then, import secondary, traceback
inside your main script, and change callscripts() like this:
def callscripts():
print "Calling Functions"
errors = open("ERRORS(S).txt", "a")
try:
secondary.test_harness()
except:
errors.write(traceback.format_exc() + '\n')
EDIT in response to comment:
At the top of your script, import traceback
, then:
def callscripts():
print "Calling Functions"
errors = open("ERRORS(S).txt", "a")
try:
execfile("data/secondary.py", {})
except:
errors.write(traceback.format_exc() + '\n')