Tom Strickland <[EMAIL PROTECTED]> wrote:
>I have a file that contains many lines, each of which consists of a string 
>of comma-separated variables, mostly floats but some strings. Each line 
>looks like an obvious tuple to me. How do I save each line of this file as a 
>tuple rather than a string? Or, is that the right way to go?

Depending on exactly what format you've got, either .split(',') on
the line, or if this is insufficient look at the csv module. You'll
then need some way of turning the list of strings both of these
will give you into the mixed float/string tuple you want, which
could be somewhat tedious. Without knowing what these lines look
like, or what they represent, I can't begin to guess how you might
go about it. Actually, I can -- I'd start by considering whether a
dict might be more appropriate than a tuple and use csv.DictReader.

-- 
\S -- [EMAIL PROTECTED] -- http://www.chaos.org.uk/~sion/
  ___  |  "Frankly I have no feelings towards penguins one way or the other"
  \X/  |    -- Arthur C. Clarke
   her nu becomeþ se bera eadward ofdun hlæddre heafdes bæce bump bump bump
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to