详解Python包(package)和目录(directory)的区别
程序员文章站
2022-06-15 19:46:46
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__.pyfile in it, which you can import normally withimport pckg. This will execute thepckg/__init__.py, whic......
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这些,我们直接可以使用目录即可。
本文地址:https://blog.csdn.net/Vermont_/article/details/107252185
推荐阅读
-
详解Python中__str__和__repr__方法的区别
-
python正则表达式函数match()和search()的区别详解
-
对python中dict和json的区别详解
-
基于python中staticmethod和classmethod的区别(详解)
-
详解python while 函数及while和for的区别
-
详解Python3中的迭代器和生成器及其区别
-
对Python中Iterator和Iterable的区别详解
-
对python内置map和six.moves.map的区别详解
-
详解Python中is和==的区别
-
Python中正则表达式match()、search()函数及match()和search()的区别详解