csv and iterator protocol

  • Thread starter Philippe C. Martin
  • Start date
P

Philippe C. Martin

Hi,

I have the following working program:

1) I import data in csv format into internal data structures (dict + list)
2) I can export back to csv
3) I can store my internal data using pickle+bz2
4) I can reload it.


Hovever I notice a factor 10 size loss using pickle.

So I would like to bzip/store in csv format but am not certain how to read
the data back as the csv module as described uses a file name in its
constructor. I would like to avoid reading the data and writing it into a
file prior to re-importing it.

Can I initialize csv with input data stored in RAM (ex: a string) ? - so far
I cannot get that to work. Or to rephrase the question, what Python "RAM"
structure supports the "iterator protocol" ?

Thanks,

Philippe
 
K

Kent Johnson

Philippe said:
Can I initialize csv with input data stored in RAM (ex: a string) ? - so far
I cannot get that to work. Or to rephrase the question, what Python "RAM"
structure supports the "iterator protocol" ?

Many, including strings, lists and dicts. For your needs, a list of strings will work, or a cStringIO initialized from your data.

Kent
 
P

Philippe C. Martin

Thanks Kent,

I had a bug in my test program: it works fine with strings

Philippe
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,241
Messages
2,571,219
Members
47,849
Latest member
RoseannKoz

Latest Threads

Top