Imagine you have a class called Human
which needs a name
to be built. Then you have a City(Human)
class which inherits Human
class where it needs a population and a list of people which consist of instantiation of that Human
class. Then a Country
class is introduced where similarly, it requires a list of cities.
I wrote this simple code but i don't know exactly how to use super()
and it produces errors related to that wrong type of inheritance.
I also want to have access to all Human
names when i'm in City
class for example.
I would appreciate any comment and help from you guys. Here's the code:
class Human:
def __init__(self, name, **kwargs):
self.name = name
class City(Human):
def __init__(self, people_list, population, **kwargs):
self.population = population
self.people = people_list
super(Human, self).__init__()
class Country(City):
def __init__(self, city_list, **kwargs):
self.city_list = city_list
super(City, self).__init__()
if __name__ == '__main__':
joe = Human("joe")
lisa = Human("lisa")
mona = Human("mona")
alex = Human("alex")
my_list01 = [joe, lisa]
my_list02 = [mona, alex]
London = City(my_list01, 2)
Leeds = City(my_list02, 2)
my_list03 = [London, Leeds]
UK = Country(my_list03)