In this article, we share the example of python implementation of student information management system specific code for your reference, the details are as follows
1. Main elements
The python kind of .py file is shown here
The first file is the one used to manage the relationships between the modules in the package in the file
The second file is the main function file, which is where the main function file calls the rest of the files and modules
The third module is the Student Information Management module.
The fourth file is the one used to store student data
The fifth file is a module for defining and displaying student information
2.Realization code
1) The first file is automatically generated by the package's administrative file and does not need to be modified.
2) Documentation
from managerSystem import *# Import the module managerSystem and use its functions. if __name__=='__main__':# Define code that can only be run in a run file before it is executed student_manager=StudentManager() student_manager.run()
3) Student Information Management Module
from student import * class StudentManager(object): def __init__(self): self.student_list = [] def run(self): self.load_student() while True: self.show_menu() ret = int(input('Please enter the numbers 1 - 7:')) if ret == 1: self.add_student() elif ret == 2: self.del_student() elif ret == 3: self.modify_student() elif ret == 4: self.search_student() elif ret == 5: self.show_student() elif ret == 6: self.save_student() elif ret == 7: break @staticmethod# This method is executed without passing any parameters def show_menu(): print('Please select the following serial number:') print('1. Adding trainees') print('2. Deletion of trainees') print('3. Modification of trainee information') print('4. Finding trainees') print('5. Display trainee information') print('6. Save trainee information') print('7. Exit the system') def add_student(self): name = input('Please enter the name of the trainee:') gender = input('Please enter the gender of the trainee:') tel = input('Please enter a phone number:') student = Student(name, gender, tel) self.student_list.append(student) # print(self.student_list) # print(student) def del_student(self): del_name = input('Please enter the name of the trainee to be deleted:') for i in self.student_list: if == del_name: self.student_list.remove(i) break else: print("No such person has been identified.) # print(self.student_list) def modify_student(self): modify_name = input('Please enter the name of the trainee to be changed:') for i in self.student_list: if == modify_name: = input('Pro enter the name of the trainee that needs to be changed:') = input('Please enter the gender of the trainee to be repaired:') = input('Please enter the cell phone number of the trainee that needs to be changed:') print(f'The modified information is{},{},{}') break else: print('The trainee to be modified does not exist') def search_student(self): searce_name = input('Please enter the name of the trainee you need to search:') for i in self.student_list: if == searce_name: print(f'name and surname:{},distinguishing between the sexes:{},cell phone number:{}') break else: print("No such person has been identified.) def show_student(self): print('Name: \t Gender: \t Cell Phone No.:') for i in self.student_list: print(f'{}\t{}\t{}') def save_student(self): f = open('', 'w') new_list = [i.__dict__ for i in self.student_list] print(new_list) (str(new_list)) () def load_student(self): # 1. Open the file: try r to open it, if there is an exception w try: f = open('', 'r') except: f = open('', 'w') else: # 2. reading data: the data read out of the file is of type String Reduced List; [{}] converts [Learner Object] data = () # String if data != '': # At this point, you need to add to determine whether the file is empty, otherwise an error will occur new_list = eval(data) self.student_list = [Student(i['name'], i['gender'], i['tel']) for i in new_list] finally: # 3. Closing the file ()
4) Files storing data do not need to be edited
5) Files are mainly a module used to store the main information about the student, as well as a way to be able to view the student's information
class Student(object): def __init__(self, name, gender, tel): = name = gender = tel def __str__(self): return f'{},{}, {}'
This is the whole content of this article.