首页 > 代码库 > Pythonclassmethodstaticmethod
Pythonclassmethodstaticmethod
class MySQL: def __init__(self,ip,port): self.ip=ip self.port=port @classmethod def from_conf(cls): import settings obj=cls(settings.ip,settings.port) return obj
class Student: def __init__(self,name,name_id,age,sex,group): self.name = name self.name_id=name_id self.age = age self.sex = sex self.group=group def tell_info(self): print(‘‘‘-------%s info NAME_ID:%s AGE:%s SEX:%s GROUP:%s ‘‘‘%(self.name,self.name_id,self.age,self.sex,self.group)) def save(self): with open(r‘%s\%s‘%(settings.student_path,self.name_id),‘wb‘)as f: res=pickle.dumps(self) f.write(res) @staticmethod def get_all(): res=os.listdir(settings.student_path) #os.listdir的结果是列表 for i in res: with open(r‘%s\%s‘%(settings.student_path,i),‘rb‘)as f: result=pickle.load(f) result.tell_info()
Pythonclassmethodstaticmethod
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。