Sandra-24 a écrit : > Lawrence D'Oliveiro wrote: > >>In article <[EMAIL PROTECTED]>, >> "Sandra-24" <[EMAIL PROTECTED]> wrote: >> >> >>>Now that is a clever little trick. I never would have guessed you can >>>assign to __class__, Python always surprises me in it's sheer >>>flexibility. >> >>That's because you're still thinking in OO terms. > > It's not quite as simple as all that. I agree that people, escpecially > people with a Java (ew) background overuse OO, when there's often > simpler ways of doing things.
Nope. I mean : they don't overuse OO, they overuse *classes*. AFAIK, OO means *object* oriented - not class oriented. There are OO languages that don't even have a notion of class. > However in this case I'm simply getting an object (an mp_request object > from mod_python) passed into my function, and before I pass it on to > the functions that make up and individual web page it is modified by > adding members and methods to add functionality. Which is a well-known design pattern called "decorator". (snip) > Sadly I'm unable to create it as a python object first, because it's > created by the time my code comes into play. So I have to resort to > using the new module to add methods. This is OK IMHO. > It works, but it has to be redone for every request, Is this really a problem ? > I thought moving > the extra functionality to another object would simplify the task. > > A > better way might be to contain the mp_request within another object and > use __getattr__ to lazily copy the inner object. I'd probably have to > first copy those few fields that are not read-only or use __setattr__ > as well. Why copy ? You could as well just use composition/delegation (also using __getattr__ - and BTW, this is another possible implementation of the decorator pattern). -- http://mail.python.org/mailman/listinfo/python-list