From: Erin S. <eri...@gm...> - 2006-11-13 07:07:32
|
On 11/13/06, Charles R Harris <cha...@gm...> wrote: > > > On 11/12/06, Erin Sheldon <eri...@gm...> wrote: > > Hi all - > > > > Thanks to everyone for the suggestions. > > I think map(tuple, list) is probably the most compact, > > but the list comprehension also works well. > > > > Because map() is proably going to disappear someday, I'll > > stick with the list comprehension. > > array( [tuple(row) for row in result], dtype=dtype) > > > > That said, is there some compelling reason that the array > > function doesn't support this operation? > > My understanding is that the array needs to be allocated up front. Since the > list comprehension is iterative it is impossible to know how big the result > is going to be. Isn't it the same with a list of tuples? But you can send that directly to the array constructor. I don't see the fundamental difference, except that the code might be simpler to write. > > BTW, it might be possible to use fromfile('name', dtype=dtype) to do what > you want if the data is stored by rows in a file. I'm reading from a database. Erin |