Elegant solution needed: Data manipulation

Jason Orendorff jason at jorendorff.com
Sat Feb 2 10:14:16 EST 2002


Mark wrote:
> What follows is what I came up with from reading the re stuff
> overnight and toying around a bit.  I hope it doesn't fall into the
> Python "anti-idiom" trap.  I'm definitely open to a communal "code
> review".

I accidentally wrote my formula like this:

  add( shoesize, mul ( height, weight ))

without a space between "add" and "(".  So it gave me
wrong answers.  (Anything that manipulates code using
regular expressions will have flaws in some cases.)

When you use regular expressions, use raw strings.
But in some cases you can use the replace
method:

  x = x.replace(name, "data['%s']" % name)

I'm a bit surprised you didn't take Steve's code and
say "Yay, I'm done!".  I'm extra surprised you didn't
reply to any of the responses to your message or
ask any followup questions.  Your approach might be
faster than Steve's (I'm not sure), but it seems a
bit more fragile.

Cheers, and enjoy Python!

## Jason Orendorff    http://www.jorendorff.com/




More information about the Python-list mailing list