views:

76

answers:

2

i have the following class

class notify():
    def __init__(self,server="localhost", port=23053):
        self.host = server
        self.port = port
        register = gntp.GNTPRegister()
        register.add_header('Application-Name',"SVN Monitor")
        register.add_notification("svnupdate",True)
        growl(register)    

    def svn_update(self, author="Unknown", files=0):  
        notice = gntp.GNTPNotice()
        notice.add_header('Application-Name',"SVN Monitor")
        notice.add_header('Notification-Name', "svnupdate")
        notice.add_header('Notification-Title',"SVN Commit")
        # notice.add_header('Notification-Icon',"")
        notice.add_header('Notification-Text',Msg)
        growl(notice)

    def growl(data):
        s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        s.connect((self.host,self.port))
        s.send(data)
        response = gntp.parse_gntp(s.recv(1024))
        print response
        s.close()    

but when ever i try to use this class via the follwoing code i get NameError: global name 'growl' is not defined

from growlnotify import *
n  = notify()
n.svn_update()

any one has an idea what is going on here ?

cheers nash

+1  A: 

The instance scope is not searched as part of scope resolution in Python. If you want to call a method on self then you must prefix it with a reference to self.

self.growl(register)
Ignacio Vazquez-Abrams
+1  A: 

growl is not a global symbol, it's a member of the notify class.

Inside the notify class, call the growl method as follows:

self.growl(notice)
Bertrand Marron