저는 2 주 동안 만 파이썬 코드를 작성해 왔기 때문에 아직 토지를 알아 냈습니다. 그러나 나는 내부적으로 무거운 것을 사용하는 것뿐만 아니라 때때로 '사용자'가 호출 할 수있는 메소드가 있다고 가정 해 봅시다 (즉, 호출 전에 인수가 이미 검사되었습니다). 다음은 현재 수행중인 작업입니다.Python : 공개 메소드가 '형제'비공개 메소드를 호출합니다.
#The method the 'user' should call:
def do_something(self, arg1, arg2, arg3):
#write code to do error checking on arg1, agr2, arg3
#raise exceptions, return codes, etc: depends on whether you are an explicit lover
#or an implicit lover, it seems. :-)
... error checking code here...
#Now call the 'brother' method that does the real work.
return self._do_something(self, arg1, arg2, arg3, arg3)
#The method other private methods should call with already validated parameters
def _do_something(self, arg1, arg2, arg3, arg3):
#don't do error checking on the parameters. get to work...
... do what you do...
return whatever you're supposed to return
이것은 논리적입니다. 이 작업을 수행하는 더 좋은 Python-ish 방법이 있습니까?
폴 파이썬에서 개인 회원에 대한 "true"를 지원하지만, 개인 두 개의 주요 밑줄을 사용하는 것 같은 멤버를 표시하기 위해 파이썬 방법은 없습니다
네, 고마워요. – TallPaul
제안 된대로 편집 된 메서드 호출. – TallPaul