Categories: links, linux, programming, python, snark, solaris, spam, sysadmin, tech, unix, web.
|
2011-09-22 An operational explanation of Python typesIn the world of new style classes, everything in Python has a type
(visible with ' Given part 4 of what you can do with metaclasses, we can now see the answer: an object's type is where Python finds special methods for it. Python does not look for special methods through the
normal attribute lookup process (where it would effectively look up
This will print ' Now we can see why everything in Python has the type that it does.
Instances of a class have a (My example above was contrived because people generally don't try to put special methods on instances. But it's easy to have a clash between a class special method and a metaclass special method, and then this does matter.) One of the nice aspects of this is that it unifies how Python does
attribute lookup for instances of classes with how it does it with
classes. There is no special magic in the interpreter to treat them
differently; how they behave is just determined by how their type
acts. Much of what looks like fundamental behavior (such as using
' Types also get involved in explicit attribute lookups, but that's a much more complicated topic and is not as core to what a type is in Python. (Well, in my opinion.)
|
These are my WanderingThoughts GettingAround This is part of CSpace, and is written by ChrisSiebenmann. * * * Atom feeds are available; see the bottom of most pages. Categories: links, linux, programming, python, snark, solaris, spam, sysadmin, tech, unix, web |