+ 1

python class error: missing 1 required positional argument: 'self'

Hey guys, I'm doing a personal project to understand classes better and I can't get past this error: TypeError: number_of_crew_members() missing 1 required positional argument: 'self'. I'm running the method using "prometheus.number_of_crew_members()" Does anyone know how I can fix this? Appreciate any help! Thanks class prometheus: num_of_crew_members = 0 def __init__(self, first, last, job_title, security_code=None): self.first = first self.last = last self.job_title = job_title self.security_code = security_code #number of crew members prometheus.num_of_crew_members += 1 # Fullname def fullname(self): return '{} {}'.format(self.first, self.last) # Crew members profile def crew_member_profile(self): return 'Name: {}, {} ---> Tile: {} ---> Security Code: {}'.format(self.last, self.first, self.job_title, self.security_code) def number_of_crew_members(self): return "Number of crew members: {}".format(prometheus.num_of_crew_members)

19th Nov 2020, 7:38 PM
David
David - avatar
3 Respuestas
+ 3
thanks NotAPythonNinja. i will. i forgot you could do this.
19th Nov 2020, 8:12 PM
David
David - avatar
+ 2
NotAPythonNinja thanks so much for your help. its works.
19th Nov 2020, 8:07 PM
David
David - avatar
+ 1
NotAPythonNinja thanks for answering. do you mean something like this: crew = prometheus.number_of_crew_members() then call “crew”?
19th Nov 2020, 8:01 PM
David
David - avatar