Skip to content
Advertisement

How do you structure python code to avoid long import statements?

example directory structure and code:

JavaScript
JavaScript
JavaScript
JavaScript

how would you go about removing the text [inside these square brackets] on the import statements?

of course, doing this kind of structure will cause this to not be possible:

JavaScript

Advertisement

Answer

The simplest is to just use a relative import. For example in utils_one.py you can do

JavaScript

You can also use .. to go up a hierarchy just like with a file system

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement