I’m writing a class that makes use of some functions inside its __init__ function and I’m not sure about the best practice of where to define those functions. I usually like to define __init__ first but if I need to use the a function/method within the __init__ then it needs to be defined first. I dont want to define it outside the class as its useless outside the class but it seems messy to me to define methods before the __init__. What are the normal conventions for this?
I’m writing a class that makes use of some functions inside its __init__ function
Share
Just add the methods to your class like every other method
No problem at all.
While it is not mentioned in the Python Style Guide IIRC, it’s convention to let
__init__be the first method in your class.