Re: [Tutor] trying to translate and ebcidic file

2011-06-15 Thread Mark Tolonen


"Prinn, Craig"  wrote in message 
news:6b49a56a6e493f4eba255f6f197f070f050e4fe...@bbh-mail1.bbh.priv...
I am looking for a way to translate and ebcidic file to ascii. Is there a 
pre-existing library for this, or do I need to do this from scratch? If

> from scratch and ideas on where to start?

There are a couple of EBCDIC codecs (see list of codecs in 
http://docs.python.org/library/codecs.html).


Try:open('file.txt').read().decode('ibm500').encode('ascii','replace')

You'll get '?' for chars ascii doesn't support.

-Mark



___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] trying to translate and ebcidic file

2011-06-14 Thread Jerry Hill
On Tue, Jun 14, 2011 at 2:40 PM, Prinn, Craig
 wrote:
> I am looking for a way to translate and ebcidic file to ascii. Is there a
> pre-existing library for this, or do I need to do this from scratch? If from
> scratch and ideas on where to start?

If the file is essentially a text file, I would read the contents in,
decode the resulting bytes to a unicode string, then encode the
unicode string to the encoding of your choice (ascii, utf-8, etc).
You'll also need to know which variant of EBCDIC you're dealing with.
I'm assuming CCSID 500.

Something like this:

input_file = open('my_ebcidic_file', 'rb')
ebcidic_bytes = input_file.read()
unicode_str = ebcidic_bytes.decode('cp500')
ascii_str = unicode_str.encode('ascii')

You can do it in less steps, but that should give you something to start with.

Jerry
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] trying to translate and ebcidic file

2011-06-14 Thread Steve Willoughby

On 14-Jun-11 11:40, Prinn, Craig wrote:

I am looking for a way to translate and ebcidic file to ascii. Is there
a pre-existing library for this, or do I need to do this from scratch?
If from scratch and ideas on where to start?


Bear in mind that there's no 100% straight-across translation, because 
ASCII and EBCDIC each has characters that the other lacks.  However, to 
translate the character codes they share in common, you could do 
something as simple as using the translation table functionality built 
in to the string class in Python, setting up a table to convert between 
one and the other.


of course, if you are on a Unix-like system, there's already a command 
for that, to convert a file "E" from EBCDIC to a file "A" in ASCII:


 $ dd if=E of=A conv=ascii

or the other way:
 $ dd if=A of=E conv=ebcdic

--
Steve Willoughby / st...@alchemy.com
"A ship in harbor is safe, but that is not what ships are built for."
PGP Fingerprint 4615 3CCE 0F29 AE6C 8FF4 CA01 73FE 997A 765D 696C
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] trying to translate and ebcidic file

2011-06-14 Thread Prinn, Craig
I am looking for a way to translate and ebcidic file to ascii. Is there a 
pre-existing library for this, or do I need to do this from scratch? If from 
scratch and ideas on where to start?
thanks

Craig Prinn
Document Solutions Manager
Office Phone 919-767-6640
Cell Phone410-320-9962
Fax  410-243-0973
3600 Clipper Mill Road
Suite 404
Baltimore, MD 21211

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor