Re: [Tutor] A CSV field is a list of integers - how to read it as such?

2013-03-06 Thread Dave Angel
On 03/06/2013 09:05 PM, DoanVietTrungAtGmail wrote: Once a csv file has been read by a csv reader (such as DictReader), it's no longer a csv file. That was an "Aha!" moment for me. The file is on disk, each row of it is in memory as a list or dict, and it's the list or dict that matters. It's

Re: [Tutor] A CSV field is a list of integers - how to read it as such?

2013-03-06 Thread DoanVietTrungAtGmail
> Once a csv file has been read by a csv reader (such as DictReader), it's > no longer a csv file. That was an "Aha!" moment for me. The file is on disk, each row of it is in memory as a list or dict, and it's the list or dict that matters. It's so obvious now. Thanks Dave. > a namedtuple is pr

Re: [Tutor] A CSV field is a list of integers - how to read it as such?

2013-03-04 Thread Steven D'Aprano
On 05/03/13 00:24, Dave Angel wrote: import array myarray = array.array('b', mylist) An array is somewhat slower than a list, I think that it's true that using a list *can* be faster, but that's only because we're comparing apples with oranges. Arrays do more work than lists. For example, u

Re: [Tutor] A CSV field is a list of integers - how to read it as such?

2013-03-04 Thread Dave Angel
On 03/04/2013 01:48 AM, DoanVietTrungAtGmail wrote: Don, Dave - Thanks for your help! Don: Thanks! I've just browsed the AST documentation, much of it goes over my head, but the ast.literal_eval helper function works beautifully for me. Dave: Again, thanks! Also, you asked "More space efficient

Re: [Tutor] A CSV field is a list of integers - how to read it as such?

2013-03-03 Thread Steven D'Aprano
On 04/03/13 17:48, DoanVietTrungAtGmail wrote: Don, Dave - Thanks for your help! Don: Thanks! I've just browsed the AST documentation, much of it goes over my head, but the ast.literal_eval helper function works beautifully for me. Dave: Again, thanks! Also, you asked "More space efficient than

Re: [Tutor] A CSV field is a list of integers - how to read it as such?

2013-03-03 Thread DoanVietTrungAtGmail
Don, Dave - Thanks for your help! Don: Thanks! I've just browsed the AST documentation, much of it goes over my head, but the ast.literal_eval helper function works beautifully for me. Dave: Again, thanks! Also, you asked "More space efficient than what?" I meant .csv versus dict, list, and objec

Re: [Tutor] A CSV field is a list of integers - how to read it as such?

2013-03-03 Thread Dave Angel
On 03/03/2013 09:24 PM, DoanVietTrungAtGmail wrote: Dear tutors I am checking out csv as a possible data structure for my records. In each record, some fields are an integer and some are a list of integers of variable length. I use csv.DictWriter to write data. When reading out using csv.DictRea

Re: [Tutor] A CSV field is a list of integers - how to read it as such?

2013-03-03 Thread Don Jennings
On Mar 3, 2013, at 9:24 PM, DoanVietTrungAtGmail wrote: > Dear tutors > > I am checking out csv as a possible data structure for my records. In each > record, some fields are an integer and some are a list of integers of > variable length. I use csv.DictWriter to write data. When reading out u