-
Notifications
You must be signed in to change notification settings - Fork 1
Python Relative Import
info-rchitect edited this page Jan 3, 2020
·
4 revisions
Here is how you can use a similar relative file import process as o1.
-
Create a sub-directory where your supporting Python source files live. You cannot name the sub-directory the same as an existing Python file in the parent directory. In this example, the top level file is
translator.pyand the sub-directory is namedtranslators. -
Place your supporting Python file(s) in the sub-directory, here is an example.
-
Add your relative import statement to the top level Python file(s), in this case the file
translator.pyis importing theIpXactclass from thetransalators/ip_xact.pyfile. Here is an example.
from .translators.ip_xact import IpXactThat is all it takes.