Meta Class

Gabriel Genellina gagsl-py2 at yahoo.com.ar
Fri Feb 1 17:33:12 EST 2008


En Fri, 01 Feb 2008 15:46:05 -0200, Trevor Johnson  
<trevorpython at gmail.com> escribió:

> I think I have a good candidate for a meta class here. Never done this
> before and would like someone to help. In the code that follows, there is
> one variable that needs to be changed: the letter 'a' as inserted in
> construction of the variable 'word'. In other applications, I will need  
> to
> change that to two variables, but they are independent within this code.  
> How
> do I go about abstracting these variables to make a meta class?

I think you totally misunderstood the metaclass concept. A class is an  
instance of its metaclass, that is, a metaclass is the "thing" used to  
create a new class. You don't even use (custom) classes in your example.

If you want to make a more generic function, that is, something that works  
for other letters instead of just 'a', you want a function parameter:

>  >>> def testing(searched_letter):
> ...   for word in wordPool:
...

and replace all occurences of 'a' with searched_letter, and 'aaa' with  
searched_letter*3

Usage: testing('a'), it should give the same results as before. Try  
testing('e') etc.

-- 
Gabriel Genellina




More information about the Python-list mailing list