私は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風の方法はありますか?
ポール