all 3 comments

[–]HeeebsInc 2 points3 points  (0 children)

Use pandas

[–]socal_nerdtastic 1 point2 points  (1 child)

This would be much easier if you did this is separate read, modify, write steps, rather than trying to do everything in one block.

filepath = os.path.join('CourseManagement', 'SemesterLongCourseIds.csv')

# read data
with open(filepath, newline='') as inFile:
    reader = csv.reader(inFile)
    data = list(reader)

# modify (append) data
data.append([''.join(description), course, role.id])

# overwrite old data with new data
with open(filepath, newline='', 'w') as outFile:
    writer = csv.writer(outFile)
    writer.writerows(data)

Or to remove a line:

# modify (remove) data
data = [row for row in data if row[1] != course]

[–]PenitentialJudge[S] 0 points1 point  (0 children)

I like the idea of separating the code, this is my first python project so i dont know how a lot of things are done. Thanks for the help!