A modest indentation proposal

Christian Tanzer tanzer at swing.co.at
Mon Dec 3 02:38:43 EST 2001


quinn at krone.ugcs.caltech.edu (Quinn Dunkan) wrote:

> For example, I'm often tempted to use __getattr__ for delegation or lazy
> evaluation or plain old getters/setters.  But (IMO) language flaws make
> __getattr__ and __setattr__ very hard to use, because of their interaction
> with all the __magic__ attributes.
(snip)
> Since new magic attributes seem to pop up every day, what about
> existing __getattr__-using code that had all the holes patched up, but
> is now going to explode because suddenly python wants to look up an
> __eq__ method where it never did before?

I fell into the same trap once or twice and nowadays I always start a
__getattr__ with:

    if name.startswith("__") and name.endswith("__"):
        raise AttributeError, name

If I really want to handle a magic attribute I can always do it
explicitly -- don't think I ever did yet. 

-- 
Christian Tanzer                                         tanzer at swing.co.at
Glasauergasse 32                                       Tel: +43 1 876 62 36
A-1130 Vienna, Austria                                 Fax: +43 1 877 66 92





More information about the Python-list mailing list