Python source file organization

I am starting a new Python project and want to follow standard conventions as close as possible. I read that, for example, import statements should be specified. But I did not find any agreement on such things as defining all function definitions before or after all class definitions. Are there any conventions for such things? Or does everyone usually just organize things like defining functions and classes in any order, it seems to make sense?

+3
source share
2 answers

No, there is no agreement for organizing functions and classes. However, there are some basic guidelines that will make your source stream better and more understandable to readers:

  • Document. No matter what you do, make sure that the use (and in some cases the implementation) of classes and functions is described in plain English)
  • Group everything that is the same. Two functions that perform similar functions? Connect them.
  • Use common sense. If the class extends another, the base class must be the first. If the function accepts an instance of the class that you defined, make sure that the class definition is defined first.

, , , Python. , Python.

0
+5

Source: https://habr.com/ru/post/1779930/


All Articles