欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

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

程序员文章站 2022-03-01 12:37:24
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 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