473,407 Members | 2,326 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,407 software developers and data experts.

recover a partly destroyed pickled structure

Hi all

I have (my mistake) overwritten the beginning of a file where a long
dictionary was pickled with another (pickled and much smaller) dictionary.
Since only 10% or so of the original and important data was overwritten, I
would be happy if I could somehow recover at least the part that I can
still see.

The situation is now the following. If I open the file in vi I can see :

(dp0
S'011'
p1
(dp2
S'profile'
p3
(lp4
F3.125
aF5.625
aF8.59375
....
#uninteresting data
....
p460
sg36
g6
sg37
S'0:00'
p461
sg39
(lp462
sg41
g6
ss. #after that line starts the data I need
aF10.0
aF10.3125
aF8.125
aF4.84375
aF4.21875
aF5.9375
.....# all data is here until the end
g4
sg215
S'12:26'
p3376
ss.
# end of old important data

Can anybody give an indication on how to do that? I tried to understand
how pickle puts these numbers on the different fields and remove the
unimportant beginning of the file to replace it with something that would
allow to unpickle the data, but did not really succeed. Read the
source (and understand it) is far beyond my python skills...

Any hint or pointer would be appreciated.

Regards,

Maurizio
Jul 18 '05 #1
1 2749
Each line you quote as "interesting" is an item in a list, denoted by
the line starting with 'a', after that is the type notation ('F', for
float), so if that's all the data you need, you can just do:

values = []
for line in lines:
line = line.strip()
assert line.startswith( 'aF' ), """Line %r doesn't start with
aF"""%(line,)
value = float(line[2:])
values.append( value )

doSomethingWithValues( values )

You can see the formats quite simply by using pickle at the command line:

In [3]: pickle.dumps( [ 2.0, 3.0] )
Out[3]: '(lp0\nF2.0\naF3.0\na.'

HTH,
Mike

Maurizio Berlusconi wrote:
Hi all

I have (my mistake) overwritten the beginning of a file where a long
dictionary was pickled with another (pickled and much smaller) dictionary.
Since only 10% or so of the original and important data was overwritten, I
would be happy if I could somehow recover at least the part that I can
still see.

....
ss. #after that line starts the data I need
aF10.0
aF10.3125
aF8.125
aF4.84375
aF4.21875
aF5.9375
....# all data is here until the end
g4
sg215
S'12:26'
p3376
ss.
# end of old important data

Can anybody give an indication on how to do that? I tried to understand
how pickle puts these numbers on the different fields and remove the
unimportant beginning of the file to replace it with something that would
allow to unpickle the data, but did not really succeed. Read the
source (and understand it) is far beyond my python skills...

Any hint or pointer would be appreciated.

Regards,

Maurizio


--
________________________________________________
Mike C. Fletcher
Designer, VR Plumber, Coder
http://www.vrplumber.com
http://blog.vrplumber.com

Jul 18 '05 #2

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

Similar topics

48
by: Joseph | last post by:
Hi I'm writing a commercial program which must be reliable. It has to do some basic reading and writing to and from files on the hard disk, and also to a floppy. I have foreseen a potential...
2
by: Nate | last post by:
Hello, I am trying to recover a SQL Server 7 database from another hard disk drive that has a corrupted Windows 2000 Advanced Server installation. I am not able to repair the corrupted Windows...
5
by: Prem K Mehrotra | last post by:
I come from Oracle background. In Oracle, when one wants to do a point in time recovery, one can specify recover database until timestmap. Oracle's database maps to a db2 subsystem, i.e., in...
5
by: Grant | last post by:
Hi Is there a way to recover deleted records from a table. A mass deletion has occurred and Access has been closed since it happened Louis
3
by: Cillies | last post by:
Hello, I have managed to delete a database, but I don't know when, it was sometime in the last 2 months. I have not created a back up. So should I start looking for a new job.
4
by: David Hirschfield | last post by:
I have a pair of programs which trade python data back and forth by pickling up lists of objects on one side (using pickle.HIGHEST_PROTOCOL), and sending that data over a TCP socket connection to...
2
by: krishnakant Mane | last post by:
hello all, I am trying a very complex kind of a task in a project. I have a knowledge management system where I need to store a lot of objects (pickled). I have to store mostly lists and...
0
by: mike_dba | last post by:
I have been testing the db2 recover command on a DB2 V8.2 Linux database. The database contains a single partition. I am not archiving logs but retaining them on disk. the backup image is to...
6
by: MLH | last post by:
Utilities to recover tbl removed from TABLE tab of database window with the DELETE key?
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: 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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.