2

I can't get my mind around this problem

Let's suppose we have a file structure

Folder
├── main_file.py
├── Subfolder
│   ├── __init__.py
│   ├── file_a.py # def foo()
│   ├── file_b.py # from file_a import foo; def bar(...use function foo())

How can I use function bar in my main_file.py without nothing going wrong, because if I only import function bar from file_b it throws me error: 'there's no module named file_a'

Thank you for answer

edit thanks, I only have trouble with some imports inside my file, so after adding the Subfolder. to all imports it works well Thank you

Jasasul
  • 39
  • 3

2 Answers2

0

You need to specify the directory you're importing from. Specify the file path like this:

from Subfolder.file_b import bar
Virdan
  • 36
  • 1
  • 6
0

You need to specify the RELATIVE directory w.r.t main_file.py. In this case you can find and import the function bar like this :

from Subfolder.file_b import bar
Utpal Dutt
  • 383
  • 3
  • 18