An object is an instance (or not)?
ben+python at benfinney.id.au
Wed Jan 28 00:39:53 CET 2015
Ned Batchelder <ned at nedbatchelder.com> writes:
> On 1/27/15 3:12 PM, Mario Figueiredo wrote:
> > This is a follow up from a previous discussion in which it is argued
> > that the following code produces the correct error message terminology,
> > considering that in Python an object is also an instance.
> I don't know what the difference is between "object" and "instance".
> An object is an instance of a class. The two words are
> interchangeable as far as I know.
Not in English grammar, IMO. To say “foo is an instance” implies the
sentence isn't finished; the term “instance” only makes sense in the
context of a relationship to some class. To say “foo is an object”
doesn't have that implication.
> A common mistake is to believe that "OOP" is a well-defined term.
> It's not it's a collection of ideas that are expressed slightly
> differently in each language.
Right. The common meaning of “object” shared by all OOP systems is
object-oriented for that. In such a system it would be true to say “foo
is an object, but is not an instance of anything”.
> > Because, from my own study of Python, I've came to realize that the
> > distinction between objects and instances of objects actually
> > exists. In Python, class objects cannot participate in OOP, only
> > their instances.
> What does "participate in OOP" mean?
To the extent I understand (and I'm confused on what that might mean as
you are), I think it's plainly false.
In Python, every class is an object. Every class has the full range of
behaviour that we expect of objects. A class just has the additional
feature that it can be instantiated.
> > This is why I say that even in Python, where a class is an object,
> > an object is not always an instance. The language itself forces that
> > distinction.
You have not, to my knowledge, shown any object (in Python 2.2 or later)
which is not an instance of some class. Python objects are always an
instance of some specific class.
\ “Books and opinions, no matter from whom they came, if they are |
`\ in opposition to human rights, are nothing but dead letters.” |
_o__) —Ernestine Rose |
More information about the Python-list