Archive - Originally posted on "The Horse's Mouth" - 2011-11-17 23:49:47 - Graham Ellis
"A Metaclass (Python) or Metatable (Lua) adds extra code / data / behaviour to an object, table, or class."
What does that mean? It means that I can define a behavior that I want to be shared, that I want to define at run-time, that I want to amend ... in a separate module / zone / table from my main class. It's flexible, powerful. In Lua, it's a vital feature if you're looking to write code using an Object Oriented paradigm, as your metatable provides you with your methods which are able to be shared between objects. In Python, it's rather esoteric - yes, useful but you'll tend to write code which all but the most hardened of programmers will end up scratching their heads over.
Anyway - new Python examples [here]. Lua example [here], and a further description with examples [here]. That latter example makes good reading on the principles for Python users as well as Lua users.
Our Lua Courses all cover Metatables. Our Python Courses do not at present cover metaclasses; your instructor will be happy to answer questions on them, demonstrate them if you ask, cover them on extra days or after class. He will raise them if they look to be useful based on your description of your applications .. but for the most part they're something that few Python application programmers will be using, however internally important they are - and it's part of a trainer's job to pick out the important things for YOU!