Say this is my package layout
Package
:: core
:: hash
:: hashgen.py
:: validate.py
:: common
:: classes.py
:: tools
:: database_validate.py
:: bot.py
:: config.py
So if I wanted to import database_validate from tools in bot.py I’d do:
from tools import database_validate
But for core/hash/hashgen, how would I import that? Because it’s slightly longer. I know I can probably just put everything in one file, but I’m curious of how to make it import from a longer folder layout.
When building a package – don’t forget the
__init__.py. This needs to be in every tree you wish to import from. In your example it should look like this..Once this is done then you can as phihag suggested
Although I don’t recommend using * per se used here for simplicity.
Check out this – Written by the man himself!