class System:
def __init__(self,code,name,price):
self.name = name
self.price = price
self.code = code
def __str__(self):
return 'Code: ' + self.code + '\tName: ' self.name + \'tPrice: ' + self.price
def choose_item(self):
count = 0
for item in self.name:
print str(count) + '\t' item.name + '\t' + item.cost
count += 1
question = raw_input('Enter the code: ')
if question == 0:
exit()
elif choice != self.code:
print 'Invalid code'
else:
index = question -1
name[index].self.choose_item()
print 'Your item has been added'
このエラーは発生しており、間違いを見ることはできません。アイテムを追加するためにコードをキー入力してアイテムを選択したいと思います。これが正しい方法であるかどうかは不明です。AttributeError: 'str'オブジェクトに属性 'name'がありません
AttributeError: 'str' object has no attribute 'name'
元のコードは変更しないでください。間違いを犯したままにしておくと、これを通過した人は、提供された回答と混同されます。 –