Using a C/C++ analogy, I want to pipe the contents of a file to stdin.
I have a Python function that prompts users for student name and grade and creates a list of lists. Instead of typing a 100 names and grades, I want to put the names and grades in a text file and provide that as input to this function. How do I do this? Code fragment below:
def enter_grades(num_students):
class_grades = []
for i in range(num_students):
class_grades.append([input(), float(input())])
print( class_grades)
return class_grades
There is a file "grades.txt" with student names and grades. Want to provide its contents as input to enter_grades().