class Foo(object):
class Bar(object):
pass
>>> foo = Foo()
>>> bar = Foo.Bar()
但是在我看来,这不是您想要的。也许您遵循的是简单的收容层次结构:
class Player(object):
def __init__(self, ... airplanes ...) # airplanes is a list of Airplane objects
...
self.airplanes = airplanes
...
class Airplane(object):
def __init__(self, ... flights ...) # flights is a list of Flight objects
...
self.flights = flights
...
class Flight(object):
def __init__(self, ... duration ...)
...
self.duration = duration
...
然后,您可以按照以下方式构建和使用对象:
player = Player(...[
Airplane(... [
Flight(...duration=10...),
Flight(...duration=15...),
] ... ),
Airplane(...[
Flight(...duration=20...),
Flight(...duration=11...),
Flight(...duration=25...),
]...),
])
player.airplanes[5].flights[6].duration = 5