Making class attributes non-case-sensitive?

Diez B. Roggisch deets at nospam.web.de
Mon Oct 13 07:48:52 EDT 2008


Rafe wrote:

> Just so I don't hijack my own thread, the issue is 'how to wrap an
> object which is not case sensitive'.
> 
> The reason I am stuck dealing with this?... The application's API is
> accessed through COM, so I don't know if I can do anything but react
> to what I get. The API was written while the app (Softimage|XSI - one
> of 3 leading 3D applications for high-end visual effects) was owned by
> Microsoft. I'm not sure if it is standard for Microsoft or just the
> way this app was implemented (perhaps because under-users were
> scripting in VBscript which is not case sensitive).
> 
> XSI allows many languages to be used via COM, even from within the
> software (there are built-in code editors). In the early days,
> VBScript was the most common scripting language used while anything
> more hard-core was done in C++ (of course the C implementation is case
> sensitive - well as far as I know). Then JScript became the most
> common, now Python is considered standard.
> 
> Anyway, the standard practice is to use mixed-case, so I need to
> adhere to it as the resulting framework I am creating needs to be
> intuitive to use (my end-user is still writing code. It's an API for
> an API I guess...)
> 
> I don't *think* I need to worry too much about performance because I'm
> not doing any serious processing, this is more about convention
> enforcement and quality control rather than number crunching. I might
> try to write something generic which gets executed by the wrappers
> __getattr__ and __setattr__, but I was hoping for some nifty
> workaround, maybe in the form of a decorator or something? Again...
> any ideas?

I still don't get the full picture - anyway, what I infer is this:

 - for your own sake, you want to stick with "proper" naming, whatever that
means

 - you can't control what will be called.

Then I'd go with the __getattr__-way, plus maybe a meta-class (or
postprocessing) that maps all attributes to a lower-case-variant as well,
so that the lookup is efficient.

Does that help?

Diez




More information about the Python-list mailing list