Abstract
Explains different Python new-style objects:
- what are the
<type 'type'>and<type 'object'>types - how user defined classes and instances are related to each other and to built-in types
- what are metaclasses
The system described is sometimes called the Python type system, or the object model.
Read The Book
-
Single HTML Page [ zip | tar.gz ]
-
Multiple HTML Page [ zip | tar.gz ]
Related
This book is part of a series:
-
Python Types and Objects [you are here]
Comments
No-one commented on this great tutorial yet? For shame!
This (along with "Python Attributes and Methods") is the most lucid explanation of Python's OO system that i know of.
Your site has very much liked me. I shall necessarily tell about him to the friends.
Sehr guten site. Alles arbeitet deutlich(klar), schon eben storungsfrei. Wer machte? Vielleicht vom Weg?
Interesting, but navigation system is a little bit confusing
Excellent tutorial! This information will be very helpful for anyone exploring the Python C API.
Very good tutorial ! Thanks for your sharing. I also created Python articles at http://pyarticles.blogspot.com
Awesome! One of the best Python article. Thanks a ton!
Great article. You really know how to put it simple, clear and entertaining. I enjoyed every word of it.
Been looking all over for something like this. Well done.
Excellent tut! Ive been searching the net for these advanced topics. These 'books' are a MUST read for any pythonist that wants to dig up that python inner black magic.
Took me a while to read and grok them, but they're excellent and exactly what I was looking for. Thanks a bunch!
This cleared up a lot of my confusion... thanks! As an earlier post put it, "Your site has very much liked me. I shall necessarily tell about him to the friends."
This book is quite unique ! After more than 200 hours of reading and self-studying of Python (and I am still bad at it), this text is of tremendous quality, even for beginners ! It is concise ; It is very explicit and well illustrated; I have not seen a text so clear about the internals of Python for months;
Some people (e.g: me) need to know how a machine work before using it: you're the one that do it best for Python !
So for anyone who thinks that "objects" and "instances" are impalpable matter that flow between classes and methods, read the book !
Just want to thank you for an excellent summary of the fundamentals of objects in Python. I'm actually a beginner to Python but have been asking myself these sort of questions (of which you answer many in your chapters) about the fundamentals of how the language works. I feel like I've surpassed many so-called experienced Python programmers who never bother with these issues and just want to get a job done. Once again, thanks a lot for this great resource.
amazingly hard to understand.
Thanks for the great tutorial. Using the word class for "type" would simplify the discussion a lot. Design behind creating the circular reltationship between type and class is not explained here. That would have really helped.
I loved this site and have learned a lot. I could use python fairly well but had some confusing points. You cleared by confusion. Are you going to write article for other parts of python? Having deep understanding/knowledge on something is one thing and conveying this to others is another. You have both. THANKS
Thanks from Czech Rupublic.
I'm quite surprised at all the praise. Coming from a C++ background, I find the "type is an object" paradigm unnecessary, but I accept it has advantages. This article ("book"? please, curb your ego) has helped me understand the situation, but not without a lot of rereading.
The first source of confusion for me is where the word "base" is introduced with no mention that it describes the subtyping relationship.
The article shows isinstance(object, type) is True but doesn't also show that isinstance(type, object) is True The solid arrow connecting 'object' and 'type' in the diagram should be double-headed.
I think the "Can skim section" note is wrong: I do understand type/subtype and object/instance and I still had to reread that section several times, and then return to it after reading the later discussion, to understand what you were talking about. "Subtype an instance"? From a C++ perspective, that makes no sense.
The solid arrow is the issubclass relationship. The dashed arrow is the isinstance relationship. The dashed arrow could be double ended, but that is not necessary because it automatically follows from the other relationships (Example 2.2).
While subclassing an instance makes no sense in C++, in Python all classes are techincally instances and so subclassing makes sense.
If coming from C++, you basically have to forget the C++ concept of classes and assume all Python classes, meta-classes and objects are like C++ instances. All these 'instances' are located in memory and hold references to each other. There are two kinds of references (or edges in this graph of objects) - isinstance and issubclass. How the objects are connected determine how they behave.
Anyway, parts of this book seem too pedantic now and can probably be reduced or simplified.
In the chapter 3 Wrap Up Section Summary. issubtype maybe a typo of issubclass or not?
thank you so much for your Python Types and Objects online book - it has clarified so much that I have been struggling with, unable to get a clear answer. your flow chart maps are very helpful
Very fine analysis and explanation. Thanks for the tutorial. If the basics are cleared then anybody can even read the python source for the libraries and understand them easily as python is that fine. Try to put your book into the Python documentation section. It will be very useful for all the eyes that watch the docs. Oh and i forgot to ask 'How is Squasher?' ;)
this is crap
the commentary can be a little too cheesy at points...