简体   繁体   中英

How can I open .ebc (ebcdic) file on my laptop via python?

UPD I have opened file and found this format. How I can decode 00000000....

I need to open.ebc file on Python. The size of this file is approximately 12GB.

I have used a huge amount of tools and Python libraries for this action, but it is obvious that I am doing something in a wrong way. I can't find suitable encoding.

I tried to read the file line by line because of it size.

Python lists two code pages for EBCDIC, "cp424" (Hebrew) and "cp500" (Western scripts).

Use it like this:

with open(path, encoding='cp500') as f:
    for line in f:
        # process one line of text

Note: if the file is 12G in size, you'll want to avoid to call f.read() or f.readlines() , as both would read the entire file into memory. On a laptop, this is likely to freeze your system. Instead, iterate over the contents line by line using Python's default line iteration.

If you just want to re-encode the file with a modern encoding, eg. the very popular UTF-8, use the following pattern:

with open(in_path, encoding='cp500') as src, open(out_path, 'w', encoding='utf8') as dest:
    dest.writelines(src)

This should re-encode the file with a low-memory footprint, as it reads, converts and writes the contents line by line.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM