[Tutor] how-to do black magic

Terry Carroll carroll@tjc.com
Fri May 16 14:00:02 2003


On Fri, 16 May 2003, Adam Groszer wrote:

> I have a list of properties let's say in a text file.
> >From this list I'd like to create a class's properties and getter/setter
> methods with a metaclass.
> Is this possible? How?

Adam --

I've also read the follow-ups, and am not quite sure what you're trying to 
do.  From the sound of it, though, I may have just solved a similar 
problem.

I have a dictionary-like object, Uninan (representing all Unicode CJK
characters), each entry of which is another dictionary-like object,
UnihanChar (each representing a particular character, each entry of which
was a particular characteristic of that character).  I have a
UnihanChar.Display method that show all information about the character,
and displays the character using Tkinter.

I wanted to be able to change all the UnihanChars' font by one call to 
Unihan; I did it by adding a __settatr__ to Unihan:

    def __setattr__(self, name, value):
        self.__dict__[name] = value
        # percolate changes to Font to contained UnihanChar instances
        if name == 'Font':                 
            for entry in self.data.keys():
                self.data[entry].Font = value

I don't know if this is quite on the lines of what you're doing, but even 
if not, maybe it will give you some ideas.

-- 
Terry Carroll        |  "To have this rare opportunity
Santa Clara, CA      |    is a rare opportunity."
carroll@tjc.com      |    - Houston Rockets' Yao Ming, on being named
Modell delendus est  |    starting center for the 2003 NBA All-Star Game