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

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这些,我们直接可以使用目录即可。

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值