Want to know the correct way to import modules with a folder
/garden
__init__.py
utilities.py
someTools.py
/plants
__init__.py
carrot.py
corn.py
Inside /plants/__init__.pyme
__all__ = ['carrot', 'corn']
from . import *
inside carrot.py
def info():
print "I'm in carrot.py"
When i do
import garden
garden.carrot.info()
I'm in carrot.py
My question is how to change the namespace for utilities.py, for example, inside carrot.pyand corn.py. I want to use the function inutilities.py
Inside carrot.pywhen i
import utilities as util
util.someFunc()
Can I customize __init__.pyin the folder with plants to import all the modules inside the garden? How are utilities and sometools? so I don’t need to import utilities in both carrot.py and corn.py and be able to use utilities?
source
share