Need suggestion to speed up code...

Brad Bollenbach bbollenbach at homenospam.com
Sat May 12 11:48:15 EDT 2001


Gah! Never mind. That's what I get for attempting to think before I've had
my morning coffee :(

"Brad Bollenbach" <bbollenbach at homenospam.com> wrote in message
news:VTcL6.780$rg6.209276 at news1.rdc1.mb.home.com...
> Is there a reason that noone mentioned the tuple function?
>
> >>> x = (1, "hey", "how's it goin, dude?")
> >>> y = tuple(x)
> >>> y[1]
> 'hey'
>
> That should do what you require.
>
> "Roy Smith" <roy at panix.com> wrote in message
> news:roy-54AC09.22222810052001 at news1.panix.com...
> > 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