Underscore/Camelcase insensitivity

Alexander Schmolck a.schmolck at gmx.net
Tue Feb 25 18:07:22 CET 2003

Alex Martelli <aleax at aleax.it> writes:

> Alexander Schmolck wrote:
> > m.faassen at vet.uu.nl (Martijn Faassen) writes:
> >> the camelCase convention. This week I was pondering making a mixin class
> >> which helps us transition underscore to camelcase automatically. So, in a
> >> way I was even serious here.
> > 
> > I've actually discovered that converting from and to camelCase is really
> > much more of a pain than you'd think (I might just be doing it stupidly).
> http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/66009
> I think I have a better solution in the way I expanded this recipe
> in the printed Cookbook (seeing a mixedcase or underscored name as
> a hidden sequence of underlying words, recovering the words, and
> joining them up again by whatever convention is required).
> But both approaches break horribly for e.g HTTPBaseHandler, finding
> it hard to gauge which of the caps are "breaks" in the word sequence
> and which are not.  Not impossible, I guess, just hard;-).

Certainly not impossible:

>>> camelSplit('HTTPBaseHandler')
['HTTP', 'base', 'handler']

# online cookbook recipe
>>> cw2us('HTTPBaseHandler')

My code might be convoluted, but it certainly tries harder :)


More information about the Python-list mailing list