Classes

sohcahtoa82 at gmail.com sohcahtoa82 at gmail.com
Fri Oct 31 02:21:13 CET 2014


On Thursday, October 30, 2014 2:37:54 PM UTC-7, Seymore4Head wrote:
> On Thu, 30 Oct 2014 14:28:19 -0700, Larry Hudson <orgnut at yahoo.com>
> wrote:
> 
> >On 10/30/2014 01:16 PM, 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.
> >>
> >You have already received the answer -- pax=pet should be pax=pet(), but I have a simple 
> >side-comment about style.  It is common Python convention to capitalize class names, IOW make 
> >this class Pet instead of class pet.  This is convention not a requirement, but it does help 
> >distinguish class names from ordinary variable names -- especially to others reading your code 
> >(as well as yourself a few days later).   ;-)
> >
> >      -=- Larry -=-
> 
> I try to take typing shortcuts and it bites me in the behind.
> Good suggestion
> Thanks

A shortcut is the fastest way to get somewhere you weren't going.

Python makes programming very easy (Compared to C/C++ and many other languages), but there are still a lot of shortcuts you can't make.



More information about the Python-list mailing list