我正在尝试打印这些car_object[objectname]
对象,但不知道该怎么做……我还有一个 Cars 类。当我这样做时,print(car_object[objectname])
我得到ObjectmeA160
<__main__.Cars object at 0x027FB970>
. 我究竟做错了什么?
def __iter__(self):
car_object = {}
cursor = self._db.execute('SELECT IDENT, MAKE, MODEL, DISPLACEMENT,
POWER, LUXURY FROM CARS')
for row in cursor:
car_object = {}
objectname = 'Object'+str(row['IDENT'])
car_object[objectname] = Cars(ident = row['IDENT'], make = row['MAKE'],
model = row['MODEL'], disp = row['DISPLACEMENT'], power = row['POWER'], luxury = row['LUXURY'])
print(car_object[objectname])
yield dict(row)
class Cars:
def __init__(self, **kwargs):
self.variables = kwargs
def set_Variable(self, k, v):
self.variables[k] = v
def get_Variable(self, k):
return self.variables.get(k, None)