Classes

Seymore4Head Seymore4Head at Hotmail.invalid
Thu Oct 30 17:00:47 EDT 2014


On Thu, 30 Oct 2014 13:34:04 -0700, Rob Gaddi
<rgaddi at technologyhighland.invalid> wrote:

>On Thu, 30 Oct 2014 16:16:51 -0400
>Seymore4Head <Seymore4Head at Hotmail.invalid> 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 <module>
>>     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()
Thanks



More information about the Python-list mailing list