Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to import module [duplicate]

Tags:

python

Possible Duplicate:
How to import the src from the tests module in python

I want to call another module which is located in another dir. My code structor is

flask_beginner/
  app.py
  models/
      __init__.py
      user.py
  tests/
      __init__.py
      user_test.py

I want to call user module from user_test.py. My user_test.py is like this..

import models.user
....

But it raise error that no module named models.user

Do you have any idea? My Python Version is 2.7.2.(with virtualenv)

Thanks in advance.

like image 582
nobinobiru Avatar asked May 02 '26 15:05

nobinobiru


1 Answers

import sys
sys.path.append('PathToModule')
import models.user
like image 200
jbaldwin Avatar answered May 04 '26 03:05

jbaldwin



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!