Procedural API inside class--scoping questions

Kevin Walzer kw at codebykevin.com
Mon Jan 11 10:54:57 EST 2010


I'm trying to make use of a Python library, aemreceive, that provides a 
procedural API. (aemreceive is a library for Python on the Mac that 
allows the application to receive and respond to Apple Events.)

My Python apps basically run in a single fooApp class, and everything 
runs inside the class. To launch the app (my apps are Tkinter-based), I 
use something like this:

if __name__== '__main__':
     app = fooApp(None)
     app.mainloop()

In keeping with aemreceive's procedural API, I've added a runCommand 
function inside the app class to provide some basic functionality in 
response to Apple Events it will set some objects/variables, then 
display the output in the app. In my code it looks like this:

     def runCommand(string):
         self.searchterm=string
         self.servertree.selection_set('Default')
         self.getInfo()

When I test this command, I get an error from Python: "self" is not 
defined.

I think I understand what is going here. All of the other functions in 
the fooApp class take "self" as a parameter, i.e. they are components of 
the class. runCommand is not, so therefore "self" is undefined. My 
question is, how can I get the values from the class (self.searchterm, 
et.al) inside the runCommand function?

Thanks,
Kevin

-- 
Kevin Walzer
Code by Kevin
http://www.codebykevin.com



More information about the Python-list mailing list