当前位置: 移动技术网 > IT编程>脚本编程>Python > 详解Python包(package)和目录(directory)的区别

详解Python包(package)和目录(directory)的区别

2020年07月12日  | 移动技术网IT编程  | 我要评论

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 with import pckg. This will execute the pckg/__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

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网