学生管理系统(面向对象)
前言
这个只是使用面向对象的方法写的 构思和学生管理系统(JSON模块)是一样的
file_manager.py
"""
Project: ClassStudent
Creator: 猫猫
Create time: 2021-03-04 08:18
IDE: PyCharm
Introduction:https://blog.youkuaiyun.com/Cantevenl/article/details/115439530
"""
base_dir = 'files/' # 定义一个变量 文件路径
# 读文件的函数
def read_file(file_name):
try:
with open(base_dir + file_name, 'r', encoding='utf8') as file:
content = file.read()
return content
except FileNotFoundError:
print('文件未找到')
def write_file(file_name):
with open(base_dir + file_name, 'w', encoding='utf8') as file:
pass
def write_json(file_name, data):
with open(base_dir + file_name, 'w', encoding='utf8') as file:
import json
json.dump(data, file)
def read_json(file_name, default_data):
try:
with open(base_dir + file_name, 'r', encoding='utf8') as file:
import json
return json.load(file)
except FileNotFoundError:
# print('文件未找到')
return default_data
tools.py
"""
Project: ClassStudent
Creator: 猫猫
Create time: 2021-03-04 08:20
IDE: PyCharm
Introduction:https://blog.youkuaiyun.com/Cantevenl/article/details/115439530
"""
# 加密密码
import hashlib
def encrypt_password(passwd, x='zhumaogouniu'):
h = hashlib.sha256()
h.update(passwd.encode('utf8'))
h.update(x.encode('utf8'))
return h.hexdigest()
model.py
"""
Project: ClassStudent
Creator: 猫猫
Create time: 2021-03-04 08:18
IDE: PyCharm
Introduction:https://blog.youkuaiyun.com/Cantevenl/article/details/115439530
"""
class Teacher(object):
def __init__(self, name, password):
import tools
self.name = name
s