473,769 Members | 2,003 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 2771
Each line you quote as "interestin g" 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 )

doSomethingWith Values( 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\naF 3.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
8506
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 problem. The program may crash unexpectedly while writing to the file. If so, my program should detect this during startup, and then (during startup) probably delete the data added to the file and redo the writing operation.
2
2955
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 2000 Advanced Server installation but the file system is intact. I have installed a new copy of SQL Server 7 onto a new hard disk and have used the sp_attach_db system stored procedure to attach the database from the old hard drive into the new...
5
3826
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 Oracle database means entire database, i.e.. all tablespaces (including indexes). I see only recover tablespace and recover indexspace (or index) commands in db2. Therefore, one has to specify all the tablespaces and indexspaces and recover them
5
29015
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
1308
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
3741
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 the receiver, who unpickles the data and uses it. So far this has been working fine, but I now need a way of separating multiple chunks of pickled binary data in the stream being sent back and forth. Questions:
2
1181
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 dictionaries into a rdbms. mostly I will be using mysql. I want to know if there is any module that can help me store a pickled object inside a blob field instead of a file. I know that pickle.dump() can store an object into a file but I can't find a...
0
1794
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 disk as well. I performed the following in order : 1. OFFLINE BACKUP <time#1> 2. Create table S.T (c1 smallint) 3. Insert several rows into S.T - values 1,2,3,4,5 4. ONLINE BACKUP <time#2> 5. Insert several more rows 6,7,8,9
6
7785
by: MLH | last post by:
Utilities to recover tbl removed from TABLE tab of database window with the DELETE key?
0
9589
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10211
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10045
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9994
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8870
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5298
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5447
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3561
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2815
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.