IOError in imported python module

99封情书 提交于 2019-12-13 04:37:30

问题


I have a module with the following folder structure

Module
-__init__.py
-analyzer.py
-lib/
-lib/models
-lib/data/

However when used from the parent directory I get an IOError for a file used in analyzer.py which is in lib/models. How can I get this fixed without copying the models and data to the parent directory


回答1:


Every Python module must have own __init__.py file:

Module
-__init__.py
-analyzer.py
-lib/
-lib/__init__.py
-lib/models/
-lib/models/__init__.py
-lib/data/
-lib/data/__init__.py

The __init__.py files are required to make Python treat the directories as containing packages. In the simplest case, __init__.py can just be an empty file.

See: https://docs.python.org/2/tutorial/modules.html#packages



来源:https://stackoverflow.com/questions/33801189/ioerror-in-imported-python-module

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!