0
根据我在this文章中看到的内容,我试图编写这段代码,但它给了我错误。调用成员函数并在python中传递带有map函数的参数
ticklabels = ax.get_xticklabels()
set_color = operator.methodcaller('set_color("b")')
ticklabels[0].set_color('b') # this runs fine
map(set_color, ticklabels) #error is here
错误代码:
map(set_color, ticklabels) AttributeError: 'Text' object has no attribute 'set_color("b")'
你不能传递参数在methodcaller功能?
是否'图(拉姆达X:x.set_color,ticklabels)'工作? – halex
@halex,是的,你的代码也可以工作,并在提到的文章中提到。我只是不想使用'lambda'。谢谢你提到这一点。 – rowman
'lambda'变体应该是'map(lambda x:x.set_color('b'),ticklabels)' –