def file_write(student_object: Student) -> bool: """Append student_object to the end of students.txt file. PARAM student_object must be an instance of class Student RETURN True if student_object was successfully appended to file""" filename = "students.txt" # FileNotFoundError will never occur, as 'a' mode will always create a new file if not existing with open(filename, "a") as file_object: file_object.write(student_object.__str__() + "\n") return True
def __str__(self): return Student.__str__(self) + ', meal plan balance: $' \ + str(self.__meal_plan_balance)
student1.print_info() student2.print_info() student3.print_info() # pprint.pprint(Student.__dict__) # pprint.pprint(student1.__dict__) student1.__dict__['name'] = 'William' print(student1.__dict__['name']) print(student1.name) print( '====================================================================================' ) print('NEW') print( '====================================================================================' ) pr1 = Professor('Donald Knuth', 42) pr1.print_info() pr1.salary = 1000 pr1.print_info() print(pr1.groups) # # print(pr1.get_group()) pr1._groups = ["Math", "CS", "ML", "AI"] # print(pr1.get_group()) print(pr1.group) print(student1.__str__()) student_str = str(student1) print(student_str)
studentClass = StudentGroup(result) print(studentClass) # This iterates through each row in the table of the .csv-file for index, row in result.iterrows(): # This line creates a Student-object out of all the # lines of data from the file student = Student(row['Name'], row['Gender'], row['Listening'], row['Reading'], row['English'], row['Phonics'], row['Running Record'], row['Homework'], row['Behavior'], row['DWS Quiz'], studentClass) # After the Student object is created, # it's simply printed to the console. print(student) # In order to make things slightly smoother for you, I decided to write # all of the information into .txt-files # Each student (with comments) are printed into THEIR OWN INDIVIDUAL # .txt-file with names such as: # << Student Number >>.txt txtFile = open(f"{index}.txt", "w+") txtFile.write(student.__str__()) txtFile.close() else: print("IMPORTED: comments.py")