String 属性错误:';str';对象没有属性';名称';

String 属性错误:';str';对象没有属性';名称';,string,python-2.7,object,attributeerror,String,Python 2.7,Object,Attributeerror,我犯了这个错误,看不出错误。我想通过键入代码来选择项目,以便添加项目。不确定这样做是否正确 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: '

我犯了这个错误,看不出错误。我想通过键入代码来选择项目,以便添加项目。不确定这样做是否正确

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'

前两个错误在此函数中
\uuu str\uuu(self)
它应该是
'\t名称:'+self.name+'\t价格:'
(您错过了
+
符号,并且没有将\t包含在单引号中。)

然后在
中选择项目(自身)
功能。(缺少+符号)


前两个错误在此函数中
\uuu str\uuu(self)
它应该是
'\t名称:'+self.name+'\t价格:'
(您错过了
+
符号,并且没有将\t包含在单引号中。)

然后在
中选择项目(自身)
功能。(缺少+符号)


谢谢@MarlonAbeykoon我已经更改了代码,仍然给我相同的错误。有没有关于修改代码的建议?@初学者:可以吗?如果是,请点击勾号接受答案。谢谢@MarlonAbeykoon我已经更改了代码,但仍然给我相同的错误。有没有关于修改代码的建议?@初学者:可以吗?如果是,请点击勾号接受答案。不要更改原始代码。请保留错误,否则任何人都将与提供的答案混淆。不要更改原始代码。请保留错误,否则任何人都会对提供的答案感到困惑。
AttributeError: 'str' object has no attribute 'name'
return 'Code: ' + self.code + '\tName: ' + self.name + '\tPrice: ' + self.price 
print str(count) + '\t' + item.name + '\t' + item.cost