Python: prefer several small modules or one larger module? [closed] Python: prefer several small modules or one larger module? [closed] python python

Python: prefer several small modules or one larger module? [closed]


My thoughts are that having separate modules helps with code clarity, and later on, if by some chance these modules grow to more than 10 lines, I won't feel so bad about having them separated.

This. Keep it the way you have it.


As a user of modules, I greatly prefer when I can include the entire module via a single import. Don't make a user of your package do multiple imports unless there's some reason to allow for importing different alternates.

BTW, there's no reason a single modules can't consist of multiple source files. The simplest case is to use an __init__.py file to simply load all the other code into the module's namespace.


Personally I find it easier to keep things like this in a single file, just for the practicality of editing a smaller number of files in my editor.

The important thing to do is treat the different pieces of code as though they were in separate files, so you ensure that you can trivially separate them later, for the reasons you cite. So for instance, don't introduce dependencies between the different pieces that will make it hard to disentangle them later.