Importing from python namespace to different folders

I have python code organized like this:

part_one
  namespace
    __init__.py
    one.py

part_two
  namespace
     __init__.py
     two.py

      

If both __init__.py

contain:

import pkg_resources
pkg_resources.declare_namespace("namespace")

      

My problem comes when I import them like this:

import sys
sys.path.append("part_one")
import namespace.one

sys.path.append("part_two")
import namespace.two # ImportError

      

The obvious fix is ​​to move path.append("part_two")

before import namespace.one

, however the first import is in the script that my company uses to configure and run ipython, so I cannot add part_two there (part_one is my company's main api, part_two is my project).

It also explains why the error occurred.

+3
python importerror


source to share


No one has answered this question yet

Check out similar questions:

5504
Does Python have a ternary conditional operator?
5231
What are metaclasses in Python?
4473
Calling an external command in Python
3790
How can I safely create a subdirectory?
3602
Does Python have a substring method "contains"?
3273
What is the difference between @staticmethod and @classmethod?
3119
What is the difference between Python list methods that are appended and expanded?
2818
Finding the index of an element by specifying the list that contains it in Python
2410
Difference between __str__ and __repr__?
1130
Importing files from different folders



All Articles
Loading...
X
Show
Funny
Dev
Pics