Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
File IO in python
import csv
from cs50 import get_string
from student import Student
# Space for students
students = []
# Prompt for students' names and dorms
for i in range(3):
name = get_string("name: ")
dorm = get_string("dorm: ")
students.append(Student(name, dorm))
with open("students.csv", "w") as file:
writer = csv.writer(file)
writer.writerow(("Name", "Dorm"))
for student in students:
writer.writerow((, student.dorm))
class Student:
def __init__(self, name, dorm): = name
self.dorm = dorm
print(f"created a new student object {} living in {self.dorm}!")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment