473,386 Members | 1,694 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

binary alternative to pickle?

I am analysing medium sized datasets with Python. At the moment, I am
processing the ASCII files into Python objects every time I run the
script, because it takes about the same time as unpickling the same data.

I think I must have overlooked some utility. In Matlab, you can save
some or all existing variables into a binary file, which loads very
quickly. Is it possible to do the same with Python? Ive looked at
cPickle, which is really slow, and marshal claims that my objects are
unmarshable. Are there other alternatives to save work in progress?

Thanks,
Darren
Jul 18 '05 #1
3 3396
Darren Dale wrote:
I think I must have overlooked some utility. In Matlab, you can save
some or all existing variables into a binary file, which loads very
quickly. Is it possible to do the same with Python? Ive looked at
cPickle, which is really slow, and marshal claims that my objects are
unmarshable. Are there other alternatives to save work in progress?


Use cPickle with one of the latest protocol versions.

--
__ Erik Max Francis && ma*@alcyone.com && http://www.alcyone.com/max/
/ \ San Jose, CA, USA && 37 20 N 121 53 W && AIM erikmaxfrancis
\__/ I grow with each breath that I take / I cherish my freedom
-- Chante Moore
Jul 18 '05 #2
>
Use cPickle with one of the latest protocol versions.


Oh, yeah. I overlooked that. Thanks.
Jul 18 '05 #3

I have a huge dataset which contains a lot of individual records
represented by class instances.

I pickle this to a file :

way #1 :
for object in objects :
cPickle.dump( object, myfile, -1 )

way #2 :
p = cPickle.Pickler( myfile, -1 )
When I try to unpickle this big file :

p = cPickle.Unpickler( open( ...
many times p.load()... display a progress counter...

Loading the file generated by #1 works fine, with linear speed.
Loading the file generated by #2 :
- the progress counter runs as fast as #1
- eats all memory, then swap
- when eating swap, the progress counter slows down a lot (of course)
- and the process must be killed to save the machine.

I'm talking lots of memory here. The pickled file is about 80 MB, when
loaded it fits into RAM no problem. However I killed the #2 when it had
already hogged about 700 Mb of RAM, and showed no sign of wanting to stop.

What's the problem ?






Jul 18 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

21
by: Sami Viitanen | last post by:
Hello, How can I check if a file is binary or text? There was some easy way but I forgot it.. Thanks in adv.
13
by: Drochom | last post by:
Hello, I have a huge problem with loading very simple structure into memory it is a list of tuples, it has 6MB and consists of 100000 elements >import cPickle >plik = open("mealy","r")...
5
by: Jacob H | last post by:
Hello all, Today I began writing a utility script that takes given binary files and puts them all into one datafile. My idea is to be able to access any binary data I want by indexing the...
7
by: Bix | last post by:
As this is my very first post, I'd like to give thanks to all who support this with their help. Hopefully, this question hasn't been answered (too many times) before... If anyone could explain...
3
by: Michael Hohn | last post by:
Hi, under python 2.2, the pickle/unpickle sequence incorrectly restores a larger data structure I have. Under Python 2.3, these structures now give an explicit exception from...
14
by: simonwittber | last post by:
I've written a simple module which serializes these python types: IntType, TupleType, StringType, FloatType, LongType, ListType, DictType It available for perusal here: ...
21
by: Mike | last post by:
Hi, The example below shows that result of a marshaled data structure is nothing but a string >>> data = {2:'two', 3:'three'} >>> import marshal >>> bytes = marshal.dumps(data) >>>...
7
by: Chi Yin Cheung | last post by:
Hi, Is there a way in python to output binary files? I need to python to write out a stream of 5 million floating point numbers, separated by some separator, but it seems that all python supports...
1
by: IceMan85 | last post by:
Hi to all, I have spent the whole morning trying, with no success to pickle an object that I have created. The error that I get is : Can't pickle 'SRE_Match' object: <_sre.SRE_Match object at...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.