import os,sys
class programmer(object):
hobby="play computer"
def __init__(self,name,age,weight):
self.name=name
self._age=age
self.__weight=weight
@classmethod
def get_hobby(cls):
return cls.hobby
@property
def get_weight(self):
return self.__weight
def self_introduce(self):
print("My name is %s \nI am %s yeas old\n"%(self.name, self._age))
if __name__=='__main__':
prog=programmer('Albert',25,80)
print(dir(prog))
print(programmer.get_hobby())
print(prog.get_weight)
print(prog._programmer__weight,prog.self_introduce)
报错原因是因为,你第19行print打印括号是中文的,改成英文的就可以。
import os,sys
class programmer(object):
hobby="play computer"
def __init__(self,name,age,weight):
self.name=name
self._age=age
self.__weight=weight
@classmethod
def get_hobby(cls):
return cls.hobby
@property
def get_weight(self):
return self.__weight
def self_introduce(self):
print("My name is %s \nI am %s yeas old\n"%(self.name, self._age))
if __name__=='__main__':
prog=programmer('Albert',25,80)
print(dir(prog))
print(programmer.get_hobby())
print(prog.get_weight)
print(prog._programmer__weight,prog.self_introduce)找详细的报错,第几行?有没有中文状态下的字符
找到root cause,谢谢!