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()
来源:CSDN
作者:SKY.AI
链接:https://blog.csdn.net/aaa_aaa1sdf/article/details/103715286