0

My folder tree looks like this:

project/
  utils/
    tools.py
  sub_project1/
      module1.py
      module2.py
  sub_project2/
      module1.py
      module2.py

I want to be able to use tools.py in my different modules in my sub-projects, but I've seen on the internet that it is not a good practice to import a module from a parent folder. Nevertheless, I can't find a good solution because I really need to use tools.py in my modules from different projects and just duplicating in the sub-project folders doesn't feel right (because I'll have to change every occurrence of tools.py in case of modification). If I don't import from the parent folder, what should I do instead ?

M.Tailleur
  • 101
  • 7
  • There is nothing wrong with importing a module from a parent folder. Your best bet would be to turn your tools into a package and install it as an external dependency in your virtual enviornment – Alexander Oct 14 '22 at 18:41

1 Answers1

0

I guess the best practice is just to have a "main" file for every sub-folder in the parent folder. This can be a bit messy if you have dozens of sub-projects but it should work fine for smaller projects.

M.Tailleur
  • 101
  • 7