How to automate accessor definition?

Patrick Maupin pmaupin at gmail.com
Sun Mar 21 19:40:42 CET 2010


On Mar 21, 11:57 am, kj <no.em... at please.post> wrote:
>
> Just accessing attributes looks a bit dangerous to me, due to bugs
> like typing
>
>   i.typo = 'foo'
>
> when what you meant is
>
>   i.type = 'foo'
>
> I tried fixing this by mucking with __setattr__, but I didn't hit
> on a satisfactory solution (basically, I couldn't find a good,
> self-maintaining, way to specify the attributes that were OK to
> set from those that weren't).  Is there anything built-in?
>

If you *really* want static typing and validation for attributes in
Python, you might check out enthought traits:  http://code.enthought.com/projects/traits/

Regards,
Pat



More information about the Python-list mailing list