Re-inserting data

Alex alex at somewhere.round.here
Wed Mar 22 02:56:00 CET 2000


> The only problem with that is I don't have any control over whether or
> not tuples are used.  I am using SQL to query data from a server and
> this is the format it uses to return the data.  Worse yet, the tuples
> are not strictly strings, but dates and numbers, also.  I am trying to
> pull a date from each tuple, convert it, and return it to the tuple
> before it gets written to a file.  Any ideas?

You can coerce the whole list back and forth between tuples and lists:

l = []
for i in range (5):
   l.append (range (i, i+3))
>>> >>> ... ... 
>>> l
[[0, 1, 2], [1, 2, 3], [2, 3, 4], [3, 4, 5], [4, 5, 6]]
>>> t = map (tuple, l)
>>> t
[(0, 1, 2), (1, 2, 3), (2, 3, 4), (3, 4, 5), (4, 5, 6)]
>>> m = map (list, t)
>>> m
[[0, 1, 2], [1, 2, 3], [2, 3, 4], [3, 4, 5], [4, 5, 6]]
>>> 

Alex.



More information about the Python-list mailing list