mommomonthewind
mommomonthewind

Reputation: 4650

Python: import from other directory - name is not defined

I looked to several related questions:

Importing python file from other directory

and

how to import module from other directory in python?

but they do not really solve my problems.

So I have

|-1.py
|-my_app
  |-a.py
  |-b.py

From 1.py I did:

import sys
sys.path.insert (0, './my_app/')
from a import *

and I have the error: name a is not defined.

How could I call the class and functions I defined in a.py and b.py from 1.py?

Many thanks

Upvotes: 1

Views: 1270

Answers (1)

blhsing
blhsing

Reputation: 107095

You need to have an __init__.py file (it can be empty) under the my_app directory for it to be an importable package.

Upvotes: 2

Related Questions