When to use Directory over Python Package?
Reddit回答:
A package is something you can import into your Python code. It's a directory with
__init__.py
file in it, which you can import normally withimport pckg
. This will execute thepckg/__init__.py
, which can again import more stuff.A directory without
__init__.py
is just a normal OS directory completely unrelated to Python. It can contain files. It's what you call folder on Windows.
个人看法:当我们想放一些可以导出的模块的时候,方能其他模块引入使用的时候,我们可以使用package;
PyCharm 在这个目录下面将会自动创建__init__.py文件。
Why not create everything as a Python Package?
不是每个子目录都有必要设置成package,比如对于docs和tests这些,我们直接可以使用目录即可。