Skip to content

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.

  1. 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.py and the sub-directory is named translators.

  2. Place your supporting Python file(s) in the sub-directory, here is an example.

  3. Add your relative import statement to the top level Python file(s), in this case the file translator.py is importing the IpXact class from the transalators/ip_xact.py file. Here is an example.

from .translators.ip_xact import IpXact

That is all it takes.

Clone this wiki locally