Making class attributes non-case-sensitive?

Rafe rafesacks at
Mon Oct 13 11:11:12 CEST 2008


I'm working within an application (making a lot of wrappers), but the
application is not case sensitive. For example, Typing,
obj.Name, or even object.naMe is all fine (as far as the app is
concerned). The problem is, If someone makes a typo, they may get an
unexpected error due accidentally calling the original attribute
instead of the wrapped version. Does anyone have a simple solution for

I can protect against some cases just by making an 'alias':
class AClass(object):
    def name(self):
        print "hello"

    Name = name

...but this doesn't protect against typos, it gets more complicated
with multi-word attribute names, and it makes my epydocs confusing to
read since all spelling versions are shown (I AM concerned about my
docs being clear, but not as much as stopping typo related errors).

I thought about using my wrapper's __getattr__ and __setattr__, but I
I am concerned about the overhead of every delegated attribute call
running a search and compare (<paramName>.lower() based compare?).

Any ideas or precedence?


- Rafe

More information about the Python-list mailing list