[Tutor] Where to put small auxiliary function

Steven D'Aprano steve at pearwood.info
Fri Jul 20 13:30:51 CEST 2012


Jose Amoreira wrote:
> Hi.
> This is a question about style. I have a class definition that calls a
> small auxiliary function. Because this function isn't used anywhere
> else, I'd like to include it inside the class definition. 


*shrug*

Then do so.

class Whatever:
     @staticmethod
     def is_odd(k):
         return k % 2 == 1


but really, this is Python, not Java. Feel free to write top level functions.



-- 
Steven



More information about the Tutor mailing list