Re: [Tutor] Classes that do operator overloading
by C.T. Matsumoto other posts by this author
Nov 7 2009 3:27AM messages near this date
Re: [Tutor] Classes that do operator overloading
|
Re: [Tutor] Classes that do operator overloading
Thanks Hugo,
Do methods like __add__, __del__, count as built-in types? I'm aware of the
rule you explained and use it and that's why when I saw:
class indexer():
def ___getitem__(self, index):
return index ** 2
I thought I was missing some special style, or rule. The class above is take
from Learning Python, and there are several other examples too.
Thanks,
T
Hugo Arts wrote:
> On Sat, Nov 7, 2009 at 10:39 AM, C.T. Matsumoto <tmatsumoto@[...].net> wrote:
>
> > yes,
> >
> > class Foo: # the book says this is a class header
> > pass
> >
> > As for my question it looks like the convention is if a class only has
> > operator overloading then the class receives a lowercase class name.
> > If the class has a mix, operator overloading and a normal method then
> > the class name gets starts with a capital.
> >
> > It's just a detail, but I wanted to know.
> >
> >
>
> class names should always be capitalized, no matter what kind of
> methods they have.
> The exceptions to this are the built-in types (int, str, list, dict,
> etc.). But if you're writing a class yourself,
> capitalize it.
>
> quoting PEP 8:
>
> Almost without exception, class names use the CapWords convention.
> Classes for internal use have a leading underscore in addition.
>
> if you want to know something, anything at all about style
> conventions, read PEP 8. It's the definitive python styleguide.
>
> http://www.python.org/dev/peps/pep-0008/
>
> Hugo
>
>
_______________________________________________
Tutor maillist - Tutor@[...].org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor
Thread:
C.T. Matsumoto
Alan Gauld
Alan Gauld
Alan Gauld
Spir
C.T. Matsumoto
Hugo Arts
C.T. Matsumoto
Hugo Arts
Tim Golden
|