Skip to main content
The 2026 Annual Developer Survey is live— take the Survey today!
Remove unnecessary tag from title
Link
grolschie

Python, how How to populate a class instance

Source Link
Calvin Hobbes

Python, how to populate a class instance

This is code I made last year that takes data from google sheets, and uses it to make a CSV and upload assessment comments and grades to an online portal. I am sure this is not the best way to do this, but it works.

How can I take the following code and put it into a class setting?

orgid = wks1.col_values(1)   # student ID in  1 = col A
names = wks1.col_values(2)   # student concat names 2= col B
mark = wks1.col_values(4)   # student mark   4 = col D
commentList = wks1.col_values(15)   # Student comments  15 = col O *****
commentList =[x.strip(' ')  for x in commentList] #removes spaces at the end of comments 

del orgid[0]
del orgid[0]
del mark[0]
del mark[0]
marklist = list(zip(orgid, mark)) #combines student ID and marks for CSV
del names[0]
del names[0]
del commentList[0]
del commentList[0]
toplist = list(zip(names, commentList)) #combines student names and comments 
sorting = lambda toplist: toplist[0]
toplist.sort(key=sorting)

I have started making a class, but this is as far as I have gotten. I don't know how to take that info and put it into the class system. The youtube videos I have found deal with the creation of classes, but not so much how to put a larger amount of data into it.

class Student:
    def __init__(self, name, orgid, mark, comment):
        self.name=name
        self.orgid=orgid
        self.mark=mark
        self.comment=comment
        

I am sure this is rather basic, but I think that is where I'm at in my learning so far.

lang-py