Everything is an object in python - object class and type class

TheDoctor dreamingforward at gmail.com
Tue Jun 2 00:54:47 EDT 2015


On Monday, June 1, 2015 at 11:09:09 PM UTC-5, rand... at fastmail.us wrote:
> On Mon, Jun 1, 2015, at 20:24, TheDoctor wrote:
> > A type is not an object in the same way an instantiated type is an object
> > -- anymore than a blueprint for a building is the building itself.
> 
> What is an object?
> 
> It's something you can call str or repr on. It's something you can
> lookup attributes from its internal dictionary and call methods on. It's
> something you can compare whether it's == to something else. It's
> something you can pass as a parameter to a function

That's good material for relating to the issue. I wish I could justify my position better, but it gets into non-computational arguments.

> In many languages, you can't do any of these things (or their
> equivalents for those languages) to a type. In others, you have to get a
> special "class object" that isn't _really_ the same thing as the type
> itself, via some special syntax like typeof(Foo) or Foo.class, and can
> only work with it through magic methods in a certain module.
> 
> In python, you can. Why is this bad or confusing?

It breaks a conceptual barrier.  It's like the difference between seeing an ASCII character symbol and knowing the 8-bit binary digits.  One is a name, the other is the data.  That's an important distinction and they shouldn't be confused in the machine (which can't happen because the machine already creates that boundary).  In the case of the reader though, they can get confused -- they're not interchangeable.  They get "lexed" in the head very differently.

Mark



More information about the Python-list mailing list