2011-04-20 3 views
0

여기 내 코드 승/클래스에서 다르게 동작 이클립스/pydev 아래에 클래스를 넣으면 enterParam과 checkStr이 정의되지 않았다는 불평을하기 시작합니다. 내가 도대체 ​​뭘 잘못하고있는 겁니까?함수 호출 대 python3에서 클래스 O를

class ParamInput: 
    #Check if the value has only allowed characters 
    def checkStr(self, value): 
      return (set(value) <= allowed) 
    #Enter parameter 
    def enterParam (self, msg) 
     value=input(msg) 
     if len(value) == 0: 
      print("Cannot be empty, try again") 
      enterParam(msg) #<==== not defined 
     if not checkStr(value): #<====not defined 
      print("incorrect symbols detected, try again") 
      enterParam(msg) #<====not defined 
     return value 

답변

4

당신은 self.enterParam()self.checkStr() 같은 방법을 호출해야합니다.

(또한 Python style guide PEP 8enter_param()check_str() 같은 이름의 방법으로 권장 있습니다. - 낙타 표기법 만 파이썬에서 클래스 이름에 사용되는 쉬웠다

+0

- 고마워요!;) 자바에서 오는을, 나는 약 잊었다 그. –

+1

이 동작에 대한 설명은 http://stackoverflow.com/a/5467009/821378을 참조하십시오. 또한 셀프에 액세스 할 필요가 없다면 일반적으로 모듈 수준에서 함수를 유지하는 것이 가장 좋습니다. 메소드를 만들 필요가 없습니다. –