Why 'class spam(object)' instead of class spam(Object)' ?
Bruno Desthuilliers
bruno.42.desthuilliers at wtf.websiteburo.oops.com
Fri Sep 7 03:22:27 EDT 2007
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 !-)
More information about the Python-list
mailing list