I’ve got a piece of code which contains a for loop to draw things from an XML file;
for evoNode in node.getElementsByTagName('evolution'): evoName = getText(evoNode.getElementsByTagName( 'type')[0].childNodes) evoId = getText(evoNode.getElementsByTagName( 'typeid')[0].childNodes) evoLevel = getText(evoNode.getElementsByTagName( 'level')[0].childNodes) evoCost = getText(evoNode.getElementsByTagName('costperlevel')[0].childNodes) evolutions.append('%s x %s' % (evoLevel, evoName))
Currently it outputs into a list called evolutions as it says in the last line of that code, for this and several other for functions with very similar functionality I need it to output into a class instead.
class evolutions: def __init__(self, evoName, evoId, evoLevel, evoCost) self.evoName = evoName self.evoId = evoId self.evoLevel = evoLevel self.evoCost = evoCost
How to create a series of instances of this class, each of which is a response from that for function? Or what is a core practical solution? This one doesn’t really need the class but one of the others really does.
I renamed your list because it shared the same name as your class and was confusing.