开发者

how to fill the paremeter into function name string for invoking?

开发者 https://www.devze.com 2023-03-16 00:59 出处:网络
I\'ve got str1 = \'foo1().foo2()\' para = [1,2] what I want is: str2 = \"foo1(1).foo2(2)\" eva开发者_运维问答l(str2)

I've got

str1 = 'foo1().foo2()'
para = [1,2]

what I want is:

str2 = "foo1(1).foo2(2)"
eva开发者_运维问答l(str2)

and sort of:

eval(str1)(1,2)

Thanks for help.


Why not just store a format string, then?

str1 = 'foo1({0}).foo2({1})'
para = [1,2]
eval(str1.format(*para)) # equivalent to eval(str1.format(1,2))
0

精彩评论

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