我想保留一個腳本中創建的對象的引用,以便在另一個腳本中使用它們(不使用擱置)。在Python中創建和檢索對象列表
我想一些接近:
腳本1
class Porsche(Car):
""" class representing a Porsche """
def __init__(self, color):
self.color = color
class Porsche_Container:
# objects here
return objects
my_Porsche = Porsche(blue)
my_Porsche2 = Porsche(red)
SCRIPT2
for object in Porsche_Container:
print object.color
RGDS,
腳本1還可以產生物體爲迭代。 – 2010-08-25 10:19:40
@katrielalex你的答案似乎很好,但我得到一個「SyntaxError:無效語法錯誤」的消息。 – Bruno 2010-08-25 10:23:19
@Guillaume Lebourgeois這個選項看起來也很合適,請你舉個例子嗎? – Bruno 2010-08-25 10:27:19