Best place for a function?
Bruno Desthuilliers
bdesth.quelquechose at free.quelquepart.fr
Wed Mar 7 18:18:04 EST 2007
Sergio Correia a écrit :
> 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?
Somewhere in your module ?-)
(snip)
If your problem is to reduce the apparent complexity of the method,
defining the function inside the method won't help that much (unless the
function by itself is short enough - and event then...). Apart from
having a direct access to the method's namespace, you don't gain much by
doing so. And if it's a an implementation function that doesn't need to
access the instance, it has no reason to be a method. Moreover, since
it's not part of neither the class or the module interface, you can
freely change your mind if and when you find a need to do so.
More information about the Python-list
mailing list