'Importing modules from sibling folder
I want to import utils_file.py into scripts_file.py. I already tried to add an empty __init__.py but it didn't work. I saw many times the solution with sys but I'm not a big fan of it. Are there other solutions? Here the structure:
applications/scripts/scripts_file.py and
applications/utils_utils_file.py
Solution 1:[1]
It depends on where you run your program. For simplicity, make sure your terminal directory is inside application. Here is a way to do it:
scripts_file.py:
import utils_file.py
#Run your functions here e.g
potato(100)
utils_file.py:
#Potato functions
def potato(num):
print(num)
Just make sure when you run your program, you run scripts_file.py.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Pratyush bindal |
