python通讯录管理系统2.0

本文介绍了如何使用Python开发一个通讯录管理系统,通过在StudentEntity目录定义实体类,DataAccess层实现数据操作,再在主程序main中调用相关功能。
摘要由CSDN通过智能技术生成

在StudentEntity目录中定义函数

class Student:
    def __init__(self,no,name,age,contact):
        self.no=no
        self.name=name
        self.age=age
        self.contact=contact
    def __str__(self):
        return "{},{},{},{}".format(self.no,self.name,self.age,self.contact)
if __name__=="__main__":
    li=Student("2021","李四",20,123456)
    print(li)

然后在DataAccess定义函数


from StudentEntity import Student
def loadStudents():
    file=open("student.txt","r",encoding="utf-8")
    lines=file.readlines()
    students=[]
    for line in lines:
        a=line.split(",")
        students.append(Student(a[0],a[1],int(a[3].strip('\n'))))
    file.close()
    return students
def saveStudents(students):
    file=open("student.txt","w",encoding="utf-8")
 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值