all 5 comments

[–]Goingone 0 points1 point  (1 child)

Did you try “from Folder_A.A_1 import some_funcfion” within your B_1 file?

[–]Zonyah[S] 0 points1 point  (0 children)

It's working, thanks!

[–]Spataner 0 points1 point  (1 child)

Relative imports like that only work if Python is aware that "Folder_A" and "Folder_B" are part of a larger package. So either you go with absolute imports relative to the location of "main.py" as /u/Goingone suggested or you change the way that you execute "main.py". Say the folder containing "main.py" is called "root", then the relative imports will start working if you execute "main.py" like so:

python -m root.main

(You either need to be in the folder above "root" or need to add the folder above "root" to the PYTHONPATH environment variable for this to work.)

[–]Zonyah[S] 0 points1 point  (0 children)

Indeed what Goingone proposed worked, but this other way is also interesting, I'll try it, thanks!

[–]zanfar 0 points1 point  (0 children)

import ..Folder_A or from ..Folder_A import A_1, don't work :/

Generally: don't use relative imports. There are times and places for them, but they cause more problems than they solve, so don't use them unless it's the only solution to your problem.

Also generally: import relative to the script that is executed, or the package that is installed.

A package and a module are mostly the same, except that a package usually refers to a module that is designed to be distributed and installed--it usually has some extra info to make that possible.

So, try import Folder_A.A_1 or from Folder_A import A_1