I often use shared comma / tab data files that might look like this:
key1,1,2.02,hello,4 key2,3,4.01,goodbye,6 ...
I could read and pre-process this in Python to a list of lists, for example:
[ [ key1, 1, 2.02, 'hello', 4 ], [ key2, 3, 4.01, 'goodbye', 6 ] ]
Sometimes I like to keep this list of lists as a pickle, as it saves different types of my records. If the pickled file is large, however, it would be great to read this list of lists in streaming mode.
In Python, to download a text file as a stream, I use the following information to print each line:
with open( 'big_text_file.txt' ) as f: for line in f: print line
Is it possible to do something like this for a Python list, i.e.:
import pickle with open( 'big_pickled_list.pkl' ) as p: for entry in pickle.load_streaming( p ): # note: pickle.load_streaming doesn't exist print entry
Is there a brine function like "load_streaming"?
python ipython pickle streaming
williampli
source share