An object is an instance (or not)?

Chris Angelico rosuav at gmail.com
Tue Jan 27 19:30:32 EST 2015


On Wed, Jan 28, 2015 at 11:17 AM, Mario Figueiredo <marfig at gmail.com> wrote:
> Means the object is capable of participating in inheritance and/or
> polymorphism. An instance of an object is capable of doing so, per its
> class definitions. Whereas a Python class object is not.
>
>     >>> class Master:
>             def func(self):
>                 pass
>
>     >>> class Sub(Master):
>             pass
>
>     >>> Sub.func()
>     TypeError: func() missing 1 required positional argument: 'self'
>
> But somehow I think you knew the answer to all these questions and were
> instead being snarky.

I have no idea what you're proving here. You just showed that the
class has a function attached to it, and you didn't provide enough
arguments to it. And types have their own set of attributes and
methods:

>>> dir(type)
['__abstractmethods__', '__base__', '__bases__', '__basicsize__',
'__call__', '__class__', '__delattr__', '__dict__', '__dictoffset__',
'__dir__', '__doc__', '__eq__', '__flags__', '__format__', '__ge__',
'__getattribute__', '__gt__', '__hash__', '__init__',
'__instancecheck__', '__itemsize__', '__le__', '__lt__', '__module__',
'__mro__', '__name__', '__ne__', '__new__', '__prepare__',
'__qualname__', '__reduce__', '__reduce_ex__', '__repr__',
'__setattr__', '__sizeof__', '__str__', '__subclasscheck__',
'__subclasses__', '__subclasshook__', '__text_signature__',
'__weakrefoffset__', 'mro']

Most of those are inherited from object, but some aren't.

What are you demonstrating?

ChrisA



More information about the Python-list mailing list