Pythonmo模块导入问题
PHP中文网
PHP中文网 2017-04-18 10:30:46
0
1
364

有一个包 pack,里面有__init__.py ,test.py
若我在__init__.py中导入 test.py 采用

import test

运行__init__.py 没问题,但在包外 导入pack 出现问题,找不到test
若采用

from . import test or from pack import test

__init__.py就找不到test,包外导入pack,就没问题,这是为什么?

PHP中文网
PHP中文网

认证高级PHP讲师

reply all(1)
洪涛

Pay attention to python’s module search process: https://docs.python.org/2/tut...

Run __init__.py to import test because the program runs in the current directory, that is, the pack directory is automatically added to the module search path.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!