If I have two modules in two packages in the same folder described below:
myfolder/
package1/
__init__.py (need to add an empty file)
module1.py (has a function test())
package2/
__init__.py
module2.py
I can use the following code in module2 to import module1
myfolder/
package1/
__init__.py (need to add an empty file)
module1.py (has a function test())
package2/
__init__.py
module2.py
I can use the following code in module2 to import module1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
import os | |
sys.path.append(os.path.join(os.path.dirname(__file__), '..')) | |
from package1.module1 import test |
No comments:
Post a Comment