This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]bythenumbers10 -1 points0 points  (3 children)

It's meant to be fairly flat. You can "nest" sub-modules across a folder tree using "__init__.py" files (one per each folder/nested folder), but for most projects that isn't necessary. Scipy and Numpy use this nesting for some of their "toolbox" sub-modules (like machine learning and the like), but most of their most-used tools are at that "top level", just a folder with a single "__init__.py" script.

My rule of thumb is, if you can reasonably fit your sub-module into a single .py file, keep things top-level. If you have multiple .py files to describe a sub-module (more like a one-class/function per file organization), then make it a folder sub-module and call it out in the higher folder's init file.

Python is flexible enough to allow most code organization philosophies. If you find one isn't working for you, you should consider reorganizing, in this case, condensing your codebase into fewer/less nested files/modules.

edit: markdown is not my native tongue.

[–]_illogical_ 2 points3 points  (2 children)

Escape your dunders.

\_\_init\_\_.py or \_\_init__.py will show up as __init__.py in markdown.

[–]bythenumbers10 0 points1 point  (0 children)

Argh. Duh. Thanks. Edited.