-1
我不断收到此错误:对象错误代码
<__main__.product object at 0x0231A7B0>
从代码:
def prnt(self):
print("\n**********************************************************")
print(self.prntlist())
print("Grand total\t\t\t\t$", self.setprice())
print("**********************************************************\n")
def prntlist(self):
x = ''
for i in self.cartlist:
x = i, "/n"
return x
,而不是执行功能prntlist它会显示错误
全码:
class product(object):
name = ''
price = 0
def __init__(self, name, price):
self.name = name
self.price = price
def prnt(self):
print("\n**********************************************************")
print("Item\t\t\t Price")
print(self.name,"............ $", self.price)
print("\n**********************************************************")
def prntline(self):
x = self.name + ".........." + self.price
return x
class cart(object):
totalprice = 0
cartlist = []
def __init__(self):
self.totalprice = totalprice
self.cartlist = []
def setprice(self):
totprice = self.totalprice
for i in self.cartlist:
self.totalprice += i.price
return totprice
def prnt(self):
print("\n**********************************************************")
print(self.prntlist())
print("Grand total\t\t\t\t$", self.setprice())
print("**********************************************************\n")
def prntlinecart(self):
print("You have purchased: ", self.prntlist())
def prntlist(self):
x = ''
for i in self.cartlist:
x = i, "/n"
return x
def additem(self, item):
self.cartlist.append(item)
print("Ah, fresh out. But we can have it shipped to your house next week")
你可以发布实际调用这些方法的代码吗?你发布的内容不是错误... – dursk 2014-12-04 02:51:13
这个'x = i,“/ n”'使x成为一个元组。不是字符串。不知道这是否会导致你的问题,但从你的代码看来,它应该是str而不是元组。 – Marcin 2014-12-04 02:51:17
prntlist()不会被执行。 – 2014-12-04 02:54:16