Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!eternal-september.org!feeder.eternal-september.org!mx02.eternal-september.org!.POSTED!not-for-mail From: Rob Gaddi Newsgroups: comp.lang.python Subject: Re: Classes Date: Thu, 30 Oct 2014 13:34:04 -0700 Organization: Highland Technology, Inc. Lines: 29 Message-ID: <20141030133404.44c0875e@rg.highlandtechnology.com> References: <51755at03r0bidjqh3qf0hhpvjr8756ill@4ax.com> Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Injection-Info: mx02.eternal-september.org; posting-host="a48e804ab85e47f9d2e8748775b64aeb"; logging-data="2050"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+u45ylV48z6FDCS/Fvtl10" X-Newsreader: Claws Mail 3.9.3 (GTK+ 2.24.23; x86_64-pc-linux-gnu) Cancel-Lock: sha1:ywFBMGvvzcLXGcxEb4FmXY+IU7U= Xref: csiph.com comp.lang.python:79970 On Thu, 30 Oct 2014 16:16:51 -0400 Seymore4Head wrote: > class pet: > def set_age(self,age): > self.age=age > def get_age(self): > return self.age > pax=pet > pax.set_age(4) > > Traceback (most recent call last): > File "C:\Functions\test.py", line 18, in > pax.set_age(4) > TypeError: set_age() missing 1 required positional argument: 'age' > > I am trying to pass 4 as the age. Obviously I am doing it wrong. > The reason your call is missing the positional argument is that 4 is being assigned to self, rather than to age, so there is no age. This is because you are trying to call a function of the class object, rather than a function of an instance of the class. pax=pet() -- Rob Gaddi, Highland Technology -- www.highlandtechnology.com Email address domain is currently out of order. See above to fix.