用Python列出+映射不返回lambda函数

时间:2019-05-07 11:55:46

标签: python python-2.7 design-patterns

我正在使用python testint Mediator pattern,但是当我使用lambda测试方法时,我不知道为什么返回None

def requestPositions(self):
        return list(map(lambda airplane: airplane.position, self.airplanes))

这就是所有模式。

我错过了return onrequestPositions方法

class TrafficTower:
    def __init__(self):
        self.airplanes = []

    def requestPositions(self):
        return list(map(lambda airplane: airplane.position, self.airplanes))

class Airplane:
    def __init__(self, position, trafficTower):
        self.position = position
        self.trafficTower = trafficTower
        self.trafficTower.airplanes.append(self)

    def requestPositions(self):
        return self.trafficTower.requestPositions()


def main():
    airplane = Airplane(10, TrafficTower())
    #FIX why don't return list
    print(airplane.requestPositions())

if __name__ == "__main__":
    main()

1 个答案:

答案 0 :(得分:2)

def requestPositions(self):
    self.trafficTower.requestPositions()

在这里缺少return