Converting binaty to ascii

A

Angelo Secchi

Any suggestions on what is the right approach to solve the problem of
converting a database in binary format to an ASCII format?
Thanks for your help
angelo



--
========================================================
Angelo Secchi PGP Key ID:EA280337
========================================================
Current Position:
Graduate Fellow Scuola Superiore S.Anna
Piazza Martiri della Liberta' 33, Pisa, 56127 Italy
ph.: +39 050 883365
email: (e-mail address removed)
========================================================

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.2 (GNU/Linux)

iD8DBQFAM1JpigTT+OooAzcRAjNOAJoDJJMtLpaIBpkMZFPlwEld64lqnACbBA7o
a7qCLCGZNsWV8ZnxEUMicGw=
=wwXy
-----END PGP SIGNATURE-----
 
M

Miki Tebeka

Hello Angelo,
Any suggestions on what is the right approach to solve the problem of
converting a database in binary format to an ASCII format?
If it's a "real" database then just issue a query with on of the
Python plugins and then save the query result to a text file.
If it's just a binary file use the `array' or `struct' modules.

HTH.
Miki
 
T

Tim Roberts

Angelo Secchi said:
Any suggestions on what is the right approach to solve the problem of
converting a database in binary format to an ASCII format?

That's not nearly enough information. What kind of database? Some
proprietary thing, or something more-or-less standard? Does it have
fields? Can you describe them? What do you want the resulting file to
looks like?

Give us details and I'm sure someone will be happy to help you with this.
 
A

Angelo Secchi

That's not nearly enough information. What kind of database? Some
proprietary thing, or something more-or-less standard? Does it have
fields? Can you describe them? What do you want the resulting file
to looks like?


Actually I think is more-or-less standard. The only detailed info I have
is a so called "tracciato record" (may be "record track" in English)
in which there is a precise description of "what is where" and how
long (I do not know precisely the unit of measure...sorry for my
ignorance) the field is but no info about format.
I was trying to use the struct module but it was not clear to me how to
do that (suggestion where I can find more help and may be examples on
this module?).

Thanks Angelo
Give us details and I'm sure someone will be happy to help you with
this.--
- Tim Roberts, (e-mail address removed)
Providenza & Boekelheide, Inc.


--
========================================================
Angelo Secchi PGP Key ID:EA280337
========================================================
Current Position:
Graduate Fellow Scuola Superiore S.Anna
Piazza Martiri della Liberta' 33, Pisa, 56127 Italy
ph.: +39 050 883365
email: (e-mail address removed)
========================================================
 
X

Xavier Combelle

Actually I think is more-or-less standard. The only detailed info I have
is a so called "tracciato record" (may be "record track" in English)
in which there is a precise description of "what is where" and how
long (I do not know precisely the unit of measure...sorry for my
ignorance) the field is but no info about format.
That would be easier with the record track.
The fact is that a binary file is never standard, in it depend a
lot of the kind of language/hardware which generate it.
The unit of measure is probably the byte

The easier case is if all your data is in ascii format.
for example, if you have a file which is named data.dat
which contain 2 records of 20 bytes each with three fields (5bytes, 10
bytes, 5 bytes)

data1DATA2_____data3'ata1'ATA2_____'ata3

you can extract it by using this code

import struct

#here the format of the record
fmt = "5s10s5s"

#caluclate the total size of the record
size = struct.calcsize(fmt)

f = file("data.dat")
#read one record
s = f.read(size)
while s:
print "read =", s
#extracct fields of the record
d1,d2,d3 = struct.unpack(fmt,s)
#use the record for whatever you want
print "unpack",d1,d2,d3
#read next record
s = f.read(size)

here the result of the script

read = data1DATA2_____data3
unpack data1 DATA2_____ data3
read = 'ata1'ATA2_____'ata3
unpack 'ata1 'ATA2_____ 'ata3


The hard point is probably to find the formart string,
but by using the infos you have and the struct help page
http://python.org/doc/2.3.3/lib/module-struct.html
you should succeed.
 

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
473,774
Messages
2,569,596
Members
45,143
Latest member
DewittMill
Top