Note that there are some explanatory texts on larger screens.

plurals
  1. POpython unbound method again
    primarykey
    data
    text
    <p>This gets me into difficult time (sorry, i am still very new to python) Thank you for any kind of help.</p> <p>The error</p> <blockquote> <pre><code>print Student.MostFrequent() TypeError: unbound method </code></pre> <p>MostFrequent() must be called with Student instance as first argument (got nothing instead)</p> </blockquote> <p>This Student.MostFrequent() is called all the way in the end (last line) and the def is last def in the class</p> <p>EDITED - Naming convention</p> <p>My long code</p> <pre><code>import csv class Student: sports = [] ftopics = [] stopics = [] choice_list = [] choice_dict = {} def __init__(self, row): self.lname, self.fname, self.ID, self.gender, self.sport, self.movie, self.movieyr, self.country, self.ftopic, self.stopic = row self.sports.append(self.sport) self.ftopics.append(self.ftopic) self.stopics.append(self.stopic) def print_information(self): return (self.lname, self.fname, self.ID, self.gender) def print_first(self): return (self.lname, self.fname, self.sport) def print_second(self): return (self.lname, self.fname, self.movie, self.movieyr) def print_third(self): return (self.lname, self.fname, self.country) def print_fourth(self): return (self.lname, self.fname, self.ftopic, self.stopic) def most_frequent(self): for choice in self.choice_list: self.choice_dict[choice] = self.choice_dict.get(choice, 0) + 1 self.mostFrequent = sorted([(v, k) for k, v in self.choice_dict.items()], reverse=True) print self.mostFrequent reader = csv.reader(open('new_mondy_csc_data_revise.csv'), delimiter=',', quotechar='"') header = tuple(reader.next()) print "%-17s|%-10s|%-6s|%s" %header[:4] print "-" * 45 students = list(map(Student, reader)) # read all remaining lines for student in students: print "%-17s|%-10s|%-6s|%3s" % student.print_information() print "%-17s|%-10s|%s" %(header[0],header[1],header[4]) print "-" * 45 for student in students: print "%-17s|%-10s|%s" %student.print_first() print "%-17s|%-10s|%-16s|%s" %(header[0],header[1],header[5],header[6]) print "-" * 45 for student in students: print "%-17s|%-10s|%-16s|%s" % student.print_second() print "%-17s|%-10s|%s" %(header[0],header[1],header[7]) print "-" * 45 for student in students: print "%-17s|%-10s|%s" %student.print_third() print "%-17s|%-10s|%-15s|%s" %(header[0],header[1],header[8],header[9]) print "-" * 45 for student in students: print "%-17s|%-10s|%-16s|%s" % student.print_fourth() k = len(students) # Printing all sports that are specified by students for s in set(Student.sports): # class attribute print s, Student.sports.count(s), round(((float(Student.sports.count(s)) / k) *100),1) # Printing sports that are not picked allsports = ['Basketball','Football','Other','Baseball','Handball','Soccer','Volleyball','I do not like sport'] allsports.sort() for s in set(allsports) - set(Student.sports): print s, 0, '0%' Student.choice_list = Student.sports X = Student() X.most_frequent() #class Search(Student): # def __init__(self): # Student.__init__ </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload