开发者

Django: Calling another modules function passed through a parameter

开发者 https://www.devze.com 2023-01-08 15:11 出处:网络
I have a list of functions as: FUNCS=[{\'someattr\':\'somedetail\', \'func\':baseapp.module.function_name}, {...}, ...]

I have a list of functions as:

FUNCS=[{'someattr':'somedetail', 'func':baseapp.module.function_name}, {...}, ...]

Unfortunately it doesnt work if i try calling the func with

FUNCS[0]['func']

I get the error

Tried function_name in module baseapp.module Error was: 'module' object has no attribute 'function_name'

I presume there must be something i'm missing with how python finds f开发者_JS百科unctions because the following does work:

   In [11]: def localfunc():
   ....:     print 'hi there'
   ....:     return

   In [13]: f=[{'func':localfunc}]

   In [16]: f[0]['func']()

   hi there

What am i missing?


I managed to find the solution.

i = __import__('baseapp.module')
m = getattr(i,'module')
return m.function_name

thanks for the help

0

精彩评论

暂无评论...
验证码 换一张
取 消