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

S

Sergio Correia

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 on class object in module __builtin__:

class object
| The most base type

So is this a class? No...
<type 'object'>

My doubts get compounded when strange stuff starts to happen:
def __init__(self):
self.x = 1<type 'type'>

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

Hope this makes any sense ;),

Sergio
 
B

Bruno Desthuilliers

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)
def __init__(self):
self.x = 1
<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 !-)
 
C

Carl Banks

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
 
S

Steve Holden

Carl said:
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" ...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 -------------
 
S

Sergio Correia

Thanks for the replies, very instructive!

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" ...
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).

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 -------------
 
C

Colin J. Williams

Steve said:
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" ...
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).

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.
 
C

Colin J. Williams

Steve said:
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" ...
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).

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.
 
B

Ben Finney

[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'.]

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

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

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,733
Messages
2,569,440
Members
44,831
Latest member
HealthSmartketoReviews

Latest Threads

Top