Making class attributes non-case-sensitive?
Diez B. Roggisch
deets at nospam.web.de
Mon Oct 13 11:15:34 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,
> 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?
Ideas? Don't do that...
Seriously: where does that code come from, who's typing it? If it is python,
then make people follow python's rules. If it is some sort of homebrewn
language you map to python, adapt the mapper to enforce lower-case and make
all your properties lower case.
More information about the Python-list