I would like to know how to take values and create instances of a an object with values for each instance taken from a line in a .txt file
I have a class called Student with values name, age and grade.
My code looks like this, but only takes values from the last line so I cannot create the classes.
class Student():
def __init__(self, name, age, grade):
self.name = name
self.age = age
self.grade = grade
with open("students.txt", "r") as f:
for line in f.readlines():
data = line.strip().replace("/n", '')
name, age, grade = data.split("|")
Each line in the .txt looks like this:
John|19|94
How would I go about this?