0

I have a project folder called Projects and inside that folder I have a file called my_functions.py. Now I have a folder named myProjects and inside there is another python file called test.py

So it is something like

-Projects-
my_functions.py
    -myProjects-
     test.py

Now I have some functions in the my functions folder let me call them f1, f2 etc.

Now, I need to take a function from my_function.py and use it inside the test.py

I have used things like

from my_functions import f1
from .my_functions import f1
from Projects.my_functions import f1

For the first one I get an error called

ModuleNotFoundError: No module named 'my_functions'

I have searched online and I find that I need to do something about _init_.py somewhere (?) The problem is, I am new in codding so I could not find where to put that module, in what way etc. So if someone can tell me what to do step by step it would be really helpful.

Thanks

enter image description here

Here how it looks

Arman Çam
  • 115
  • 7

2 Answers2

0

you have to go up 1 directory.

from ..my_functions import f1

the same question here

Eric Echemane
  • 94
  • 1
  • 9
0

What worked for me is inserting the folder's path. Now many computer scientist will get angry maybe for doing this but

import sys
sys.path.insert(1,r'pathofcode')

then from ... import ... it will work.

ombk
  • 2,036
  • 1
  • 4
  • 16