为什么python设计时要有__init__.py才视为包
2017-12-13 20:20
405 查看
this is done to prevent directories with a common name, such as string, from unintentionally hiding valid modules that occur later on the module search path.
大致的理解是:
可能会有一些文件夹,比如有个专门放字符串的文件夹叫string,如果所有目录都视为包的话,import string可能就会覆盖python的string,而产生错误.而只有带init.py的才视为包的话,专门放字符串的文件夹string里肯定不会放一个init.py,就不会覆盖python的string.
大致的理解是:
可能会有一些文件夹,比如有个专门放字符串的文件夹叫string,如果所有目录都视为包的话,import string可能就会覆盖python的string,而产生错误.而只有带init.py的才视为包的话,专门放字符串的文件夹string里肯定不会放一个init.py,就不会覆盖python的string.
相关文章推荐
- Python模块包中__init__.py文件的作用
- Python模块包中__init__.py文件的作用
- java.lang.NoSuchMethodError: java.lang.NoSuchMethodError: org.python.core.PyBuiltinFunctionSet.<init
- [Python]__init__.py 使用
- python __init__.py
- Python模块包中__init__.py文件的作用
- <转>Python: __init__.py 用法
- Python针对特定服务定制的代理工具V2.0----------(__init__.py与Run.py)
- python __init__.py
- Python模块包中__init__.py文件的作用
- Python的__init__.py 文件
- python的__init__.py
- 谈谈python中的__init__.py
- python-__init__.py 与模块对象的关系
- /usr/lib/python2.7/site-packages/requests/__init__.py:91: RequestsDependencyWarning: urllib3 (1.22) or chardet (2.2.1) doesn't match a supported version!
- Python包和__init__.py文件
- Python __init__.py 作用详解
- Python3.5 __init__.py
- Python中的__init__.py与模块导入
- Python __init__.py 作用详解