2010-05-14 6 views
1

난 다음 클래스점점 전역 이름 정의되지 않은 오류

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()  

을 가지고 있지만 내가 때라도 코드를 통해이 클래스를 사용하려고 그 어느 때 내가 NameError: global name 'growl' is not defined

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

를 얻을 수있는 하나의 아이디어를 가지고 무엇을 여기 가니?

환호 내쉬

답변

3

인스턴스 범위는 파이썬에서 범위 해상도의 일부로 검색되지 않습니다. self에 메서드를 호출하려면 self에 대한 참조를 접두사로 사용해야합니다.

self.growl(register) 
1

growl IT는 notify 클래스의 멤버의 글로벌 상징이 아니다. 다음과 같이 notify 클래스 내부

growl 메소드를 호출

self.growl(notice) 
관련 문제