With a project structure like this:

├─main.py
└─src
    ├─dep1.py
    └─dep2.py

where the contents of each file is as follows:

main.py: import src.dep1 as firstdep; print("Total success")

dep1.py: import dep2 as seconddeb; print("success 1/3")

dep2.py: print("success 2/3")

Is the best way to do this creating an __init__.py file in src and importing src.dep2 in dep1.py? or is this a bad idea?

  • 🇨🇦 tunetardis@piefed.ca
    link
    fedilink
    English
    arrow-up
    1
    ·
    9 hours ago

    I was just trying to make sure that this is ok and won’t tangle up my code later on.

    I guess the main issue there is Python doesn’t like circular dependencies? Like if you try to import dep2 from dep1 and dep1 from dep2, you’re going to have a problem. You’d essentially have to refactor your code to have a dep3 that both can import to use the common functionality I guess.