I'm Sure There's A Better Way
Tim Daneliuk
tundra at tundraware.com
Sun Jul 8 20:10:01 EDT 2001
Bengt Richter wrote:
>
Thanks to all who answered! A fertitle bunch of minds 'round here....
The response that gets it all (despite my fuzzy definition) was mailed
to me privately. I deconstructed it (well really, reinvented it from
scratch myself) to make sure I understood what was going on.
And the winner is...
^-?((\d+(\.\d{2})?)|(\.\d{2}))$
To be really fussy, the \. should really be a string constant which
is conatenated into the remainder substrings so that other delimiters
could be used when I18Ning the code.
Just for the record - I knew when I started that a re was a better way to do
this. Although I've programmed a lot in other languages, I am still in
the process of absorbing python, and I had not yet attacked its re
capabilities so I decided to hand code it. Now that I look at the re
implementation, I realize I should have started there because it is so
much more compact and elegant.
In any case, it was a nice tutorial exercise which made me learn an
essential piece of python.
I'm writing a complete (small) application which does keyboard I/O,
saves state to disk, does meaningful arithmetic and so on. My intention
is to put it up on the web when done so others can use it to see something
a bit less trivial than the examples which are common in tutorials.
Once again, many thanks to all who kindly took the time to respond.
------------------------------------------------------------------------------
Tim Daneliuk
tundra at tundraware.com
More information about the Python-list
mailing list