I can't use this
import foo
method_to_call = getattr(foo, 'bar')
result = method_to_call()
because module name is hardcoded and I can't use this
module = __import__('foo')
func = getattr(module, 'bar')
func()
because module is nested.
I tried this
customer = 'jci'
module = __import__('customer.{customer_name}.gt'.format(customer_name=customer_name)) # AttributeError: module 'customer' has no attribute 'get_gt'
#module = __import__('customer.{customer_name}'.format(customer_name=customer_name), fromlist=['gt']) # AttributeError: module 'customer.jci' has no attribute 'get_gt'
#module = __import__('customer.{customer_name}.gt'.format(customer_name=customer_name), fromlist=[]) # AttributeError: module 'customer' has no attribute 'get_gt'
func = getattr(module, 'get_gt')
gt = func()
but failed with errors, specified in comment along with each variant.
get_gt() is a function inside gt.py file inside customer/jci directory. Each directory has empty __init__.py inside.
The following hardcoded code works:
import customer.jci.gt as g
gt = g.get_gt()
How to overcome?