Я писал код на Python всего пару недель, так что я все еще разбираюсь в том, что лежит на земле. Но допустим, у меня есть метод, который МОЖЕТ вызываться «пользователем» иногда, а также использоваться HEAVILY для внутреннего использования (т. Е. Аргументы уже проверены перед вызовом). Вот что я сейчас делаю:
#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?
Пол