首先,我们可以将对象添加到Python字典中吗?其次,我们如何打印对象的属性。 有我的代码从字典打印对象的属性-python
在我c.py
class C(object):
def __init__(self):
self.wage = 0.0
def setwage(self,wage):
self.wage=wage
def getwage(self):
return self.wage
在我a.py
import c
dustin = c.C()
dustin.setwage(6.9)
dic={}
# can I add dustin as an object into dic?
dic['1st employee']=dustin
for a in dic.items():
# I want to print dustin object's attribute wage
print("wage:", a.getwage())
你怎么可能有如此高的声誉,并不能解决像这样简单的事情? –
@詹姆斯米尔一个*编辑*问题不是一个*问* – alko
哦,我明白了吗?!我很困惑:) –