@classmethod question

Ivan Illarionov ivan.illarionov at gmail.com
Tue Apr 29 17:35:11 EDT 2008


On Tue, 29 Apr 2008 14:30:08 -0600, Scott SA wrote:

> With that said, your reply is amazingly helpful in my quest to
> understand python, Django, etc. Django is the ORM I referred to, so the
> material you have written helps explain a few things.

This was my intention. Django ORM uses Pyhton classes to represent tables 
and instances to represent rows. And they do it in a way very similat to 
what I had showed.

Another note about classmethods: they are almost the same thing as 
methods of metaclasses. Classmethods are more simple to understand but at 
the same time they touch very complex and, as Guido call it, 'brain-
exploding' topic.

>  I'm a little vague on the interaction of the IngredientsDescrptor VS 
IngredientsManager. I gather the 'Descriptor' class is called via the 
__get__ which then does the instance check. Could this have been done in 
the 'Manager' class?

The descriptor trick is only needed to prevent instances from calling
Manager methods. Custom descriptors are little more than just classes
and AFAIK it's better to keep them separated.

> I have been learning a lot from the Django code and other applications
> written within it. Still, some things just don't seem to gel, even after
> a host of google searches. I've not loked at the Google Apps stuff, but
> will follow your advice.

I think that it's better to keep things as simple as possible (other 
solutions in this thread are definetly more practical) and
don't try to use classmethods, custom descriptors and metaclasses
unless you *really* need this stuff. AFAIK all these
metaprogramming tricks make sense only for frameworks and for learning
Python, but make very little or no sense for smaller apps.

-- 
Ivan



More information about the Python-list mailing list