python 类

廉价感情. 提交于 2020-01-28 13:44:30
class w_contacts: 
    def __init__(self, someones_name, someones_phone, someones_job, someones_age): 
        self.name=someones_name 
        self.phone=someones_phone 
        self.job=someones_job 
        self.age=someones_age 
    def save(self): 
        with open('contacts.txt', 'a') as f: 
            f.write("name: {}\nphone: {}\njob: {}\nage: {}".format(self.name, self.phone, self.job, self.age)) 

    def load(self): 
        print("name: {}\nphone: {}\njob: {}\nage: {}".format(self.name, self.phone, self.job, self.age)) 

contact = w_add_address('www', 123456789, 'DLP', 19)
contact.save()
contact.load()


class w_add_address(w_contacts): 
    def __init__(self, n, p, j, a, someones_address): 
        wzb_contacts.__init__(self, n, p, j, a) 
        self.address = someones_address 
    def save(self): 
        with open('contacts.txt', 'a') as f: 
        f.write("name: {}  phone: {}   job: {}  age: {}  address: {}".format(self.name, self.phone, self.job, self.age, self.address))  
    def load(self): 
        print("name: {}\nphone: {}\njob: {}\nage: {}\nadd: {}".format(self.name, self.phone, self.job, self.age, self.address)) 


contact = w_add_address('www', 123456789, 'DLP', 19, 'NewYork.US')
contact.save()
contact.load()


 

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!