开发者

Django: Calling another modules function passed through a parameter

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜