Python之报错AttributeError:'CocaCola' object has no attribute 'local_logo'

试运行class类的代码如下,然而有报错信息:AttributeError:'CocaCola' object has no attribute 'local_logo'
class CocaCola():
    formula = ['caffeine','sugar','water','soda']
    def __init__(self):
        self.local_logo = '可口可乐' 

    def drink(self):    # HERE!
        print('Energy!')        

coke = CocaCola()
print(coke.local_logo)
Python脚本没有问题,问题出在.pyc文件
问题解决办法:1.python脚本命名时不要和python预留字,模块名等相同;2.删除该库的.pyc文件,重新运行代码
如何遍历删除pyc文件?

你可能感兴趣的:(python,Python)