S
Sergio Correia
I'm writing a class, where one of the methods is kinda complex. The
method uses a function which I know for certain will not be used
anywhere else. This function does not require anything from self, only
the args passed by the method.
Where should I put the function?
a) Inside the module but outside the class (to avoid cluttering it;
besides the function does not require to access any property or method
of the class).
# mymodule.py
def _myfunction():
...
class myclass(object):
def mymethod(self):
...
spam = _myfunction()
...
b) Inside the class but outside the method
# mymodule.py
class myclass(object):
def _myfunction(self):
...
def mymethod(self):
...
spam = self._myfunction()
...
c) Inside the method:
# mymodule.py
class myclass(object):
...
def mymethod(self):
def _myfunction(self):
...
...
spam = self._myfunction()
...
I'm new to python (and couldn't find anything about this in PEP 8).
What would you suggest me?
Thanks
Sergio
method uses a function which I know for certain will not be used
anywhere else. This function does not require anything from self, only
the args passed by the method.
Where should I put the function?
a) Inside the module but outside the class (to avoid cluttering it;
besides the function does not require to access any property or method
of the class).
# mymodule.py
def _myfunction():
...
class myclass(object):
def mymethod(self):
...
spam = _myfunction()
...
b) Inside the class but outside the method
# mymodule.py
class myclass(object):
def _myfunction(self):
...
def mymethod(self):
...
spam = self._myfunction()
...
c) Inside the method:
# mymodule.py
class myclass(object):
...
def mymethod(self):
def _myfunction(self):
...
...
spam = self._myfunction()
...
I'm new to python (and couldn't find anything about this in PEP 8).
What would you suggest me?
Thanks
Sergio