Student
and Students
- class gradelib.Student(pid: str, name: str | None = None)
Represents a student.
- pid
The student’s PID (identification string).
- Type:
str
- name
The student’s name. If not available, this will be None.
- Type:
Optional[str]
Notes
When a
Student
instance is printed, the student’s name is displayed if available; however, when twoStudent
instances are compared for equality, the.pid
attribute is used.Used in the index of tables in the
Gradebook
class. This allows code like:gradebook.points_earned.loc['A1000234', 'homework 03']
which looks up the the number points marked for Homework 01 by student ‘A1000234’. But when the table is printed, the student’s name will appear instead of their PID.
If the name is not available, the name attribute will be None.
- class gradelib.Students(students: Sequence[Student])
A sequence of
Student
instances.This behaves like a list of
Student
instances, but also provides afind()
method that allows you to look up a student by (part of) their name.- find(pattern: str) Student
Finds a student from a substring of their name.
The search is case-insensitive.
- Parameters:
pattern (str) – A pattern to search for in the student’s name. All students whose (lowercased) names contain this pattern as a substring will be considered matches.
- Returns:
The matching student.
- Return type:
- Raises:
ValueError – If no student matches, or if more than one student matches.