0

I've written a few tools to run inside a python environment, specifically Autodesk Maya (A 3d animation package software). Generally i like to build my tools with the same folder structure as scene below.

I was wondring, how would i properly write my 'import' statements in the utils/general.py file if i wanted it to import views/objects.py without conflicting and trying to import from the wrong tool?

ToolA
    - views/
        objects.py
    - utils/
        general.py
    main.py


ToolB
    - views/
        objects.py
    - utils/
        general.py
    main.py
JokerMartini
  • 5,674
  • 9
  • 83
  • 193
  • One could use relative imports -- something like `from ..views import objects` – jkr Apr 22 '21 at 15:41
  • Does that avoid the python environment from importing from the wrong location? – JokerMartini Apr 22 '21 at 15:42
  • When executing the general.py file with this `from .models import models` i get the following error `attempted relative import with no known parent package` – JokerMartini Apr 22 '21 at 15:46

1 Answers1

1

You might want to look into the package/module concepts for Python. Specifically, adding __init__.py files may help your imports.

See this answer for somewhere to get started: https://stackoverflow.com/a/4116384/3856731

Eric Canton
  • 324
  • 2
  • 10