Python Map in Class functions
Very simple
I have this:
for i in self.Abilities:
i.OnTime开发者_如何学Gor(amount)
Can i have something like this instead?
map(Ability.OnTimer,self.Abilities,amount)
I want to use map with class functions but i can't get it to work.
You should use map
to calculate a list of values, not for its side effects. If you're performing a sequence of actions, it's more readable to use the for
loop. People will more easily understand the intent of your code.
You could use functools.partial
to provide arguments to a function before calling it:
from functools import partial
map(partial(Ability.OnTimer, amount = amount), self.Abilities)
But do you really think this would be more readable? And mind that map
is lazy in Python 3!
精彩评论