How do I organize methods in a class in Python?

How should (or is it a pure way) organize methods in Python?

I always set the method __init__, then any other methods follow __foo__(What do you call?). But then it leads to a mess.

+5
source share
4 answers

I use two strategies:

  • an editor that can dump code, so you don’t need to see it.
  • I divide the large classes into smaller ones, where everyone does only one thing, and then creates my application from these small blocks.
+1
source

, __init__, .

+3

:

: (__init__)

: __

-: , "get"

-: , "set"

-: ( , -, , .. - - )

, , . , , , .

+3

I'm not sure whether the official standard is, but I always put the method __init__, then my own methods, followed by any embedded attachments, which I plan to implement ( __str__, __eq__, etc.). I am trying to group methods using similar functionality and arrange inline modules the same way in all classes.

0
source

All Articles