我在Python中遇到了類問題。 我想知道如何調用在其他python程序模塊中創建的對象。如何調用在模塊中創建的對象
讓我來舉個例子。我在「class_module.py」文件
def objectCase():
object1 = class_name("object1")
object2 = class_name("object2")
object3 = class_name("object3")
def other_objectCase():
other_object1 = class_name("other_object1")
other_object2 = class_name("other_object2")
other_object3 = class_name("other_object3")
隨着from class_module.py import *
擁有這些對象,我想如果我使用objectCase()
功能,我在我的節目,這些對象(object1, object2, object3)
,如果我用otherobjectCase()
功能,我呼籲所有otherobject
。 但事實並非如此。 問題是什麼?
我怎麼能保持相同的名字出現在函數(因此「object1」,「對象2」,而不是「一」, 「b」)自動? – 2012-03-21 16:23:29
@SniperWolf:基本上沒有。 – 2012-03-21 17:10:42