Skip to content
Advertisement

Import functions from another directory

I am running a python script (app.py) where I have to use two functions from another script (src.py), located inside another directory. The structure is the following:

JavaScript

I am using, in app.py, the following lines:

JavaScript

to access to the functions odd_all, even_all declared inside src.py. However, I get the error: ModuleNotFoundError: No module named 'src'.

How could I solve this problem?

Advertisement

Answer

I managed to solve the problem. The issue was that PROJECT is a Posixpath object, while SYS accepts only strings. Therefore, the solution was just to transform PROJECT to string:

JavaScript

Now everything works perfectly.

Advertisement