Need suggestion to speed up code...
Roy Smith
roy at panix.com
Thu May 10 22:22:28 EDT 2001
I need to split up a string into a list of fields. The strings are value
lists from SQL statements, and look something like this:
(1, 'foo', 'bar', 34, 3.14159, 'an imbedded comma, this sting has', 'this
one isn''t so easy either')
If it wasn't for the fact that I need to handle commas and quotes imbedded
in quoted strings, it would be trivial -- just a call to string.split.
But, as it is, the best I can figure out is to walk the string, character
by character, keeping track of what state I'm in (parsing an integer,
parsing a floating point, or parsing a quoted string). It works, but
profiling shows it's the bottleneck in my whole program.
Anybody have any idea for a better way to do this?
If I really had to, I suppose I could write this bit in C as an extension
module, but I'd rather do a pure python implementation to keep it portable.
More information about the Python-list
mailing list