James Hartley
2015-11-07 22:09:19 UTC
The Python 3 tutorial discusses relative imports at:
https://docs.python.org/3/tutorial/modules.html#intra-package-references
I have the following directory structure for a package in development:
+ outer_package/
+ __init__.py
+ inner_package
| + __init__.py
| + myclass.py
+ collateral_directory
+ arbitrary_tool.py
arbitrary_tool.py needs to instantiate the class MyClass found in
myclass.py. I have made MyClass accessible by adding the following to
inner_package/__init__.py:
from myclass import MyClass
Within arbitrary_tool.py, I have attempted the following:
from ..inner_package import MyClass
...but executing with Python 3.4 yields the following stack trace:
Traceback (most recent call last):
File "./arbitrary_tool.py", line 5, in <module>
from ..inner_package import MyClass
SystemError: Parent module '' not loaded, cannot perform relative import
Suggestions on how to solve this would be most certainly welcomed!
_______________________________________________
Tutor maillist - ***@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor
https://docs.python.org/3/tutorial/modules.html#intra-package-references
I have the following directory structure for a package in development:
+ outer_package/
+ __init__.py
+ inner_package
| + __init__.py
| + myclass.py
+ collateral_directory
+ arbitrary_tool.py
arbitrary_tool.py needs to instantiate the class MyClass found in
myclass.py. I have made MyClass accessible by adding the following to
inner_package/__init__.py:
from myclass import MyClass
Within arbitrary_tool.py, I have attempted the following:
from ..inner_package import MyClass
...but executing with Python 3.4 yields the following stack trace:
Traceback (most recent call last):
File "./arbitrary_tool.py", line 5, in <module>
from ..inner_package import MyClass
SystemError: Parent module '' not loaded, cannot perform relative import
Suggestions on how to solve this would be most certainly welcomed!
_______________________________________________
Tutor maillist - ***@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor