Proper function naming and import in Python -
i've developed project package/module/function structure resembles one:
project/ │--mainfunc.py | └───functions/ │--__init__.py |--func_caller.py │ ├───subfolder1/ │ │--__init__.py │ │--func11.py │ │--func12.py │ └───subfolder2/ │--__init__.py |--func21.py |--func22.py
each of funcxx.py
modules contains python function inside, named e.g.:
# /project/functions/subfolder1/func11.py def do_func11(args): # return some_value
the func_caller.py
file calls functions defined in each of funcxx.py
modules 1 @ time. top section of func_caller.py
(where imports are) looks like:
from subfolder1.func11 import do_func11 df11 subfolder1.func11 import do_func12 df12 subfolder2.func21 import do_func21 df21 subfolder2.func22 import do_func22 df22
this seems unnecessarily complicated way this. though of naming functions inside each funcxx.py
module main()
, able import them with:
import subfolder2.func22 df22
but results in:
typeerror: 'module' object not callable
what proper way this?
try this:
from subfolder2.func22 import name_of_func
Comments
Post a Comment