如何在Python中组织对象,属性,方法的层次结构?

时间:2013-03-08 11:30:48

标签: python oop hierarchy

从JS转向Python,需要在某个层次结构树中组织数据。作为OOP的新手,请温柔。请参阅问题示例:

class City(self):
    def __init__(self):
        self.Dubrovnik = "veryOldCity"
        self.Dubai = "brandNew"
        self.Barcelona = "beautiful"
        self.zebra = some_specific_Object

    def accidentHappened(self) :
        carCrash = None
        if manBitesDog() :
            return True

    def manBitesDog(self):
        if angryStockbroker.bitesDog(terrier) :
            return True

    def streetsInCity(self, cty) :
        allStreats = [list of streets in cty]
        return allStreats

    def mainStreet(self, thatCity):
        list_of_streets = streetsInCity(thatCity)
        for i in list_of_streets :
            if len(i) > 5 :
                return i

    def crossRoads(self, street, cty):
        if street is in cty :
            if street.hasCrossroad() is True :
                return True
            else :
                return False

// I would like to build hierarchy tree like below
placeInTown = City.Dubrovnik.mainStreet().crossRoads().zebra

// and use it like that
if City.Dubrovnik.accidentHappened() in placeInTown : 
    ThenSendAnAmbulance(placeInTown)

0 个答案:

没有答案