Questions to the FAQ

John Lenton jlenton at gmail.com
Tue Jul 13 23:12:45 EDT 2004


On Tue, 13 Jul 2004 20:12:48 +0000 (UTC), Josef Wolf <jw at raven.inka.de> wrote:
> 
> I'm new to python, so my first readings were the tutorial and the FAQs.
> I got confused by some FAQ entries. Maybe some expert can help to clear the
> confusion?
> 
> - FAQ entry 6.5: "What is delegation?"
> 
>   AFAICS, the example in this FAQ-entry should create a derived class from
>   the file class. Therefore, shouldn't the first line of this class
>   definition read "class UpperOut(file):"?
> 
>   How come self.__outfile to be the base class?

no, UpperOut isn't a file, it _has_ a file. It passes all messages on
to the file, except for write, which it mangles a bit before passing
it on, too. You could do that with subclassing too, now that you can
subclass file:

    class UpperOut(file):
        def write(self, s):
            super(UpperOut, self).write(s.upper())

which takes you nicely back to your next question.

-- 
John Lenton (jlenton at gmail.com) -- Random fortune:
bash: fortune: command not found



More information about the Python-list mailing list