質問

Following my previous question, how can I import a module that is in a folder at the same level as the file importing it? I need to get to my models folder but importing it isn't working:

$ 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

My project structure looks like this:

/
 - generate_test_data.py
 - app/
 -- __init__.py
 -- models.py
役に立ちましたか?

解決

from app.models import *

should do the trick

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top