Classes

Seymore4Head Seymore4Head at Hotmail.invalid
Thu Oct 30 22:00:09 CET 2014


On Thu, 30 Oct 2014 13:33:01 -0700 (PDT), sohcahtoa82 at gmail.com wrote:

>On Thursday, October 30, 2014 1:19:57 PM UTC-7, 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 <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 line `pax=pet` doesn't create an instance of your pet class, it creates essentially a copy of the class definition.
>
>You need `pax=pet()`
>
>Or preferably, `pax = pet()`.  The spaces are optional, but they make it more readable.

Thanks



More information about the Python-list mailing list