• python
  • javascript
  • reactjs
  • sql
  • c#
  • java
Facebook Twitter Instagram
Devs Fixed
  • python
  • javascript
  • reactjs
  • sql
  • c#
  • java
Devs Fixed
Home » Resolved: Import python module from another folder, with main directory having a “-“

Resolved: Import python module from another folder, with main directory having a “-“

0
By Isaac Tonny on 18/06/2022 Issue
Share
Facebook Twitter LinkedIn

Question:

I have a workspace called “bi-etl”. The structure is as follows:
The parameter_update.py is intended to import file_a.py and file_b.py from the utils folder, which as you can see, is not in the same folder as parameter_update.py which is in the googlesheet folder.
Following the link: Importing files from different folder
I tried the following but none seems to work so far.
Method 1: (Content of parameter_update.py)
returns ModuleNotFoundError: No module named 'file_a'
Trying another method,
based on “from application.app.folder.file import func_name”
(content of parameter_update.py)
returns

Answer:

Perhaps not the most graceful solution but I have found one using the sys library.
I added the module to the path, then used import statement for the module name.
An example:

If you have better answer, please add a comment about this, thank you!

python
Share. Facebook Twitter LinkedIn

Related Posts

Resolved: Reshape tensors of unknown shape with tf.function

26/03/2023

Resolved: Use Svelte Component as Slot

26/03/2023

Resolved: Vaadin 14.9 – Redirect on Session Destroy Event

26/03/2023

Leave A Reply

© 2023 DEVSFIX.COM

Type above and press Enter to search. Press Esc to cancel.