如何从文件夹导入模块

时间:2014-03-19 16:46:08

标签: python module python-import

根据我的previous问题,如何导入文件夹中与导入文件相同级别的模块?我需要访问我的模型文件夹,但导入它不能正常工作:

$ python generate_test_data.py 
Traceback (most recent call last):
  File "generate_test_data.py", line 6, in <module>
    from models import *
ImportError: No module named models
Exception KeyError: KeyError(48562256,) in <module 'threading' from '/usr/lib/python2.7/threading.pyc'> ignored

我的项目结构如下:

/
 - generate_test_data.py
 - app/
 -- __init__.py
 -- models.py

1 个答案:

答案 0 :(得分:1)

from app.models import *

应该做的伎俩

相关问题