I am still a bit confused by issues of scope. I have a class and a logging function outside that class. When I try to call that logging function, I get an error which says:
Traceback (most recent call last):
File "F:\wxComTool10.py", line 2336, in CommandCallback
self.SendCommand(self.selection, "")
File "F:\wxComTool10.py", line 277, in SendCommand
self.ProcessCommand(command, arguments)
File "F:\wxComTool10.py", line 288, in ProcessCommand
LogMessage("Doing it",'111')
File "F:\wxComTool10.py", line 39, in LogMessage
self.outputbox.SetLabel(message)
NameError: global name 'self' is not defined
The relevant code looks like this:
import stuff
def LogMessage(message, whichfiles):
'''This function logs a message which is passed into it. The whichfiles
variable determines to where the message gets logged: doswindow, outputfile, outputwin.'''
if whichfiles == '000':
LogMessage("Why did you call this function if you weren't going to log to anywhere?",101)
elif whichfiles == '100':
print message
elif whichfiles == '110':
print message
outfile.write(message)
elif whichfiles == '111':
print message
outfile.write(message)
self.outputbox.SetLabel(message)
class ComboBoxPanel(wxPanel):
def __init__(self, parent, ID = -1, size = wxDefaultSize, style= -1):
wxPanel.__init__(self, parent, ID, wxDefaultPosition,size=(480,180),style=wxSUNKEN_BORDER)
self.frame=parent
EVT_CLOSE(self, parent.OnExit)
[bunch of wxPython which create the gui]
def SendCommand(self, command, arguments):
self.ProcessCommand(command, arguments)
def ProcessCommand(self, command, parameters):
returnedval = ""
i=0
args = parameters.split()
for count in args:
i+=1
self.numparams = i
LogMessage("Doing it",'111')
[snip]
I hope I gave you enough code to help me figure this out. How do I call a function that is outside the class inside a function that is inside a class?
--vicki
P.S. I really want to do bitwise ops to determine which places to log to. That is log to the places that are represented by the bits that are on, but I haven't learned how to do that in Python yet. I googled, but I haven't found it yet. If someone would give me an idea of where to find an example of this, I'd appreciate it.