B
Bitswapper
So I have a parent and child class:
class Map(object):
def __init__(self, name=''):
self.mapName = name
self.rules = {}
class Rule(Map):
def __init__(self, number):
Map.__init__(self)
self.number = number
def __repr__(self):
return "Map " + self.mapName + " rule number " + str(self.number)
if __name__ == "__main__":
map = Map("thismap")
rule = Rule(1)
map.rules[rule.number] = rule
with the above:
$ python -i inherit.py
I have tried adding:
map.rules[2] = Rule(2)
but that still gets:
$ python -i inherit.py
and:
map.rule = Rule(3)
which also doesn't really get me what I'm looking for:
It seems to me what I'm trying to do is link an arbitrary child instance toan arbitrary instance of a parent class, which in this case would be handyBecause I'd like to populate a map with rules and print the rules including the parent map name for each rule. I'm just not sure how I would go about doing this in python.
Any thoughts are welcome, and thanks in advance
class Map(object):
def __init__(self, name=''):
self.mapName = name
self.rules = {}
class Rule(Map):
def __init__(self, number):
Map.__init__(self)
self.number = number
def __repr__(self):
return "Map " + self.mapName + " rule number " + str(self.number)
if __name__ == "__main__":
map = Map("thismap")
rule = Rule(1)
map.rules[rule.number] = rule
with the above:
$ python -i inherit.py
map.rules {1: Map rule number 1}
map.rules[1] Map rule number 1
I have tried adding:
map.rules[2] = Rule(2)
but that still gets:
$ python -i inherit.py
and:
map.rule = Rule(3)
which also doesn't really get me what I'm looking for:
It seems to me what I'm trying to do is link an arbitrary child instance toan arbitrary instance of a parent class, which in this case would be handyBecause I'd like to populate a map with rules and print the rules including the parent map name for each rule. I'm just not sure how I would go about doing this in python.
Any thoughts are welcome, and thanks in advance