Why 'class spam(object)' instead of class spam(Object)' ?

Discussion in 'Python' started by Sergio Correia, Sep 7, 2007.

  1. Hi, I'm kinda new to Python (that means, I'm a total noob here), but
    have one doubt which is more about consistency that anything else.

    Why if PEP 8 says that "Almost without exception, class names use the
    CapWords convention", does the most basic class, object, is lowercase?

    I found a thread about this:
    http://mail.python.org/pipermail/python-list/2007-April/437365.html
    where its stated that -object- is actually a type, not a class; but
    the idea still doesn't convince me.

    If i create a class Spam using -object- as a parent class, I would
    expect -object- to be a class, not a type as in type(object) (what is
    the difference between both btw?). But, on the other hand, if I do
    help(object), I get:

    >>> help(object)

    Help on class object in module __builtin__:

    class object
    | The most base type

    So is this a class? No...

    >>> object

    <type 'object'>

    My doubts get compounded when strange stuff starts to happen:

    >>> class Eggs(object):

    def __init__(self):
    self.x = 1
    >>> type(Eggs)

    <type 'type'>

    Type 'type'? What is that supposed to mean?

    Hope this makes any sense ;),

    Sergio
    Sergio Correia, Sep 7, 2007
    #1
    1. Advertising

  2. Sergio Correia a écrit :
    > Hi, I'm kinda new to Python (that means, I'm a total noob here), but
    > have one doubt which is more about consistency that anything else.
    >
    > Why if PEP 8 says that "Almost without exception, class names use the
    > CapWords convention", does the most basic class, object, is lowercase?


    Because it is an exception ?-)

    Notice that all builtin types (list, dict, set, str, unicode, int, long,
    float, tuple, file, object, type, function, classmethod, staticmethod,
    property etc) are lower-case.

    (snip interrogations about "object"'s type)

    >>>> class Eggs(object):

    > def __init__(self):
    > self.x = 1
    >>>> type(Eggs)

    > <type 'type'>
    >
    > Type 'type'? What is that supposed to mean?


    type(Eggs) is roughly equivalent to Eggs.__class__, ie it returns the
    class of the Eggs class object, IOW the metaclass. In Python, classes
    are objects, so they are themselves instances of a class - by default,
    for new-style classes, instances of the class 'type'. In case you
    wonder, class 'type' is an instance of itself.


    > Hope this makes any sense ;),


    Idem !-)
    Bruno Desthuilliers, Sep 7, 2007
    #2
    1. Advertising

  3. Sergio Correia

    Carl Banks Guest

    On Fri, 07 Sep 2007 01:30:00 -0500, Sergio Correia wrote:
    > Hi, I'm kinda new to Python (that means, I'm a total noob here), but
    > have one doubt which is more about consistency that anything else.
    >
    > Why if PEP 8 says that "Almost without exception, class names use the
    > CapWords convention", does the most basic class, object, is lowercase?


    It said "almost". :)


    > I found a thread about this:
    > http://mail.python.org/pipermail/python-list/2007-April/437365.html
    > where its stated that -object- is actually a type, not a class; but the
    > idea still doesn't convince me.


    There's a false dichotomy there: it's not an either-or situation. Almost
    everyone would agree that new-style classes, defined by the Python class
    statement, are both classes and types. Some might squabble over whether
    object is class, but it has nothing to do with why object is spelled in
    lower-case.

    The reason why "object" is lower case is because built-in types are
    spelled in lower-case. Why are built-in types lower case? Because many
    built-in types were originially functions. For example, "int" and "str"
    were once functions. When these symbols became the names of their
    respective types, they kept the lower-case spelling, and it became
    convention for built-in types to be spelled lower-case.


    Carl Banks
    Carl Banks, Sep 7, 2007
    #3
  4. Sergio Correia

    Steve Holden Guest

    Carl Banks wrote:
    > On Fri, 07 Sep 2007 01:30:00 -0500, Sergio Correia wrote:
    >> Hi, I'm kinda new to Python (that means, I'm a total noob here), but
    >> have one doubt which is more about consistency that anything else.
    >>
    >> Why if PEP 8 says that "Almost without exception, class names use the
    >> CapWords convention", does the most basic class, object, is lowercase?

    >
    > It said "almost". :)
    >

    Indeed it did, and never forget that most of PEP 8 was derived from an
    essay by Guido whose original title was "A Foolish Consistency is the
    Hobgoblin of Little Minds" ...
    >
    >> I found a thread about this:
    >> http://mail.python.org/pipermail/python-list/2007-April/437365.html
    >> where its stated that -object- is actually a type, not a class; but the
    >> idea still doesn't convince me.

    >

    You don't have to be convinced. You just have to do what the PEP says
    yourself and ignore the people who *haven't* done what it says
    (particularly if they are core Python developers).

    > There's a false dichotomy there: it's not an either-or situation. Almost
    > everyone would agree that new-style classes, defined by the Python class
    > statement, are both classes and types. Some might squabble over whether
    > object is class, but it has nothing to do with why object is spelled in
    > lower-case.
    >
    > The reason why "object" is lower case is because built-in types are
    > spelled in lower-case. Why are built-in types lower case? Because many
    > built-in types were originially functions. For example, "int" and "str"
    > were once functions. When these symbols became the names of their
    > respective types, they kept the lower-case spelling, and it became
    > convention for built-in types to be spelled lower-case.
    >

    In other words: "Get over it" ;-)

    regards
    Steve
    --
    Steve Holden +1 571 484 6266 +1 800 494 3119
    Holden Web LLC/Ltd http://www.holdenweb.com
    Skype: holdenweb http://del.icio.us/steve.holden
    --------------- Asciimercial ------------------
    Get on the web: Blog, lens and tag the Internet
    Many services currently offer free registration
    ----------- Thank You for Reading -------------
    Steve Holden, Sep 7, 2007
    #4
  5. Thanks for the replies, very instructive!

    On 9/7/07, Steve Holden <> wrote:
    > Carl Banks wrote:
    > > On Fri, 07 Sep 2007 01:30:00 -0500, Sergio Correia wrote:
    > >> Hi, I'm kinda new to Python (that means, I'm a total noob here), but
    > >> have one doubt which is more about consistency that anything else.
    > >>
    > >> Why if PEP 8 says that "Almost without exception, class names use the
    > >> CapWords convention", does the most basic class, object, is lowercase?

    > >
    > > It said "almost". :)
    > >

    > Indeed it did, and never forget that most of PEP 8 was derived from an
    > essay by Guido whose original title was "A Foolish Consistency is the
    > Hobgoblin of Little Minds" ...
    > >
    > >> I found a thread about this:
    > >> http://mail.python.org/pipermail/python-list/2007-April/437365.html
    > >> where its stated that -object- is actually a type, not a class; but the
    > >> idea still doesn't convince me.

    > >

    > You don't have to be convinced. You just have to do what the PEP says
    > yourself and ignore the people who *haven't* done what it says
    > (particularly if they are core Python developers).
    >
    > > There's a false dichotomy there: it's not an either-or situation. Almost
    > > everyone would agree that new-style classes, defined by the Python class
    > > statement, are both classes and types. Some might squabble over whether
    > > object is class, but it has nothing to do with why object is spelled in
    > > lower-case.
    > >
    > > The reason why "object" is lower case is because built-in types are
    > > spelled in lower-case. Why are built-in types lower case? Because many
    > > built-in types were originially functions. For example, "int" and "str"
    > > were once functions. When these symbols became the names of their
    > > respective types, they kept the lower-case spelling, and it became
    > > convention for built-in types to be spelled lower-case.
    > >

    > In other words: "Get over it" ;-)
    >
    > regards
    > Steve
    > --
    > Steve Holden +1 571 484 6266 +1 800 494 3119
    > Holden Web LLC/Ltd http://www.holdenweb.com
    > Skype: holdenweb http://del.icio.us/steve.holden
    > --------------- Asciimercial ------------------
    > Get on the web: Blog, lens and tag the Internet
    > Many services currently offer free registration
    > ----------- Thank You for Reading -------------
    >
    > --
    > http://mail.python.org/mailman/listinfo/python-list
    >
    Sergio Correia, Sep 8, 2007
    #5
  6. Steve Holden wrote:
    > Carl Banks wrote:
    >> On Fri, 07 Sep 2007 01:30:00 -0500, Sergio Correia wrote:
    >>> Hi, I'm kinda new to Python (that means, I'm a total noob here), but
    >>> have one doubt which is more about consistency that anything else.
    >>>
    >>> Why if PEP 8 says that "Almost without exception, class names use the
    >>> CapWords convention", does the most basic class, object, is lowercase?

    >> It said "almost". :)
    >>

    > Indeed it did, and never forget that most of PEP 8 was derived from an
    > essay by Guido whose original title was "A Foolish Consistency is the
    > Hobgoblin of Little Minds" ...
    >>> I found a thread about this:
    >>> http://mail.python.org/pipermail/python-list/2007-April/437365.html
    >>> where its stated that -object- is actually a type, not a class; but the
    >>> idea still doesn't convince me.

    > You don't have to be convinced. You just have to do what the PEP says
    > yourself and ignore the people who *haven't* done what it says
    > (particularly if they are core Python developers).
    >
    >> There's a false dichotomy there: it's not an either-or situation. Almost
    >> everyone would agree that new-style classes, defined by the Python class
    >> statement, are both classes and types. Some might squabble over whether
    >> object is class, but it has nothing to do with why object is spelled in
    >> lower-case.
    >>
    >> The reason why "object" is lower case is because built-in types are
    >> spelled in lower-case. Why are built-in types lower case? Because many
    >> built-in types were originially functions. For example, "int" and "str"
    >> were once functions. When these symbols became the names of their
    >> respective types, they kept the lower-case spelling, and it became
    >> convention for built-in types to be spelled lower-case.
    >>

    > In other words: "Get over it" ;-)
    >
    > regards
    > Steve

    Surely Python 3000 gives the opportunity to introduce some consistency.

    Does the user care whether an object is implemented in C?

    Colin W.
    Colin J. Williams, Sep 18, 2007
    #6
  7. Steve Holden wrote:
    > Carl Banks wrote:
    >> On Fri, 07 Sep 2007 01:30:00 -0500, Sergio Correia wrote:
    >>> Hi, I'm kinda new to Python (that means, I'm a total noob here), but
    >>> have one doubt which is more about consistency that anything else.
    >>>
    >>> Why if PEP 8 says that "Almost without exception, class names use the
    >>> CapWords convention", does the most basic class, object, is lowercase?

    >> It said "almost". :)
    >>

    > Indeed it did, and never forget that most of PEP 8 was derived from an
    > essay by Guido whose original title was "A Foolish Consistency is the
    > Hobgoblin of Little Minds" ...
    >>> I found a thread about this:
    >>> http://mail.python.org/pipermail/python-list/2007-April/437365.html
    >>> where its stated that -object- is actually a type, not a class; but the
    >>> idea still doesn't convince me.

    > You don't have to be convinced. You just have to do what the PEP says
    > yourself and ignore the people who *haven't* done what it says
    > (particularly if they are core Python developers).
    >
    >> There's a false dichotomy there: it's not an either-or situation. Almost
    >> everyone would agree that new-style classes, defined by the Python class
    >> statement, are both classes and types. Some might squabble over whether
    >> object is class, but it has nothing to do with why object is spelled in
    >> lower-case.
    >>
    >> The reason why "object" is lower case is because built-in types are
    >> spelled in lower-case. Why are built-in types lower case? Because many
    >> built-in types were originially functions. For example, "int" and "str"
    >> were once functions. When these symbols became the names of their
    >> respective types, they kept the lower-case spelling, and it became
    >> convention for built-in types to be spelled lower-case.
    >>

    > In other words: "Get over it" ;-)
    >
    > regards
    > Steve

    Surely Python 3000 gives the opportunity to introduce some consistency.

    Does the user care whether an object is implemented in C?

    Colin W.
    Colin J. Williams, Sep 18, 2007
    #7
  8. Sergio Correia

    Ben Finney Guest

    [Colin, you posted your message to both of 'comp.lang.python' and
    'gmane.comp.python.general'. The latter is merely a view on the
    former, and your message appears in exactly the same places if you
    post only to 'comp.lang.python'.]

    "Colin J. Williams" <> writes:

    > > Carl Banks wrote:
    > >> The reason why "object" is lower case is because built-in types
    > >> are spelled in lower-case.


    > Does the user care whether an object is implemented in C?


    Probably not. But they probably do care that the type is built-in.

    --
    \ "The trouble with the rat race is that even if you win, you're |
    `\ still a rat." -- Jane Wagner, via Lily Tomlin |
    _o__) |
    Ben Finney
    Ben Finney, Sep 18, 2007
    #8
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Rene Pijlman
    Replies:
    22
    Views:
    698
    Fredrik Lundh
    Dec 10, 2003
  2. Mr. SweatyFinger

    why why why why why

    Mr. SweatyFinger, Nov 28, 2006, in forum: ASP .Net
    Replies:
    4
    Views:
    837
    Mark Rae
    Dec 21, 2006
  3. Mr. SweatyFinger
    Replies:
    2
    Views:
    1,656
    Smokey Grindel
    Dec 2, 2006
  4. Replies:
    3
    Views:
    442
  5. David Binnie
    Replies:
    2
    Views:
    433
    Rich Webb
    May 22, 2009
Loading...

Share This Page