The `ebcdic` package provides additional EBCDIC codecs for Python, primarily facilitating data exchange with legacy mainframe systems. EBCDIC (Extended Binary Coded Decimal Interchange Code) is a family of character encodings distinct from ASCII and Unicode. It is intended for use in scenarios where interoperability with EBCDIC-native systems is required. The current version is 2.0.1, with releases tied to Python version compatibility.
pip install ebcdicVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to encode a standard Python string to EBCDIC bytes using a specific EBCDIC code page (e.g., 'cp1141') and then decode EBCDIC bytes back to a Unicode string. The `ebcdic` package extends Python's built-in `str.encode()` and `bytes.decode()` methods with additional EBCDIC code page support.
Ensure your Python environment is 3.9+ to use `ebcdic` 2.0.1. For older Python versions, explicitly install an earlier `ebcdic` version (e.g., `pip install ebcdic==1.1.1` for Python 3.4-3.8).
Use `ebcdic.ignored_codec_names()` to see which codecs are provided by the standard library and thus 'ignored' by this package. If specific mappings are critical, test thoroughly or consider manual encoding/decoding if conflicts arise.
Always verify the exact EBCDIC code page used by the source system for your data. This information is crucial for accurate encoding and decoding operations.
Always pass the appropriate EBCDIC code page to the `encoding` parameter of `open()` when reading or writing EBCDIC files: `with open('file.ebcdic', 'r', encoding='cp1047') as f:`.Install the package using pip: `pip install ebcdic`
Ensure the `ebcdic` package is installed (`pip install ebcdic`). Verify the exact EBCDIC codepage name against the list of supported codecs provided by the `ebcdic` library or Python's `codecs` documentation. For example, `bytes_data.decode('cp037')` or `string_data.encode('cp1141')`.Explicitly specify the correct EBCDIC codepage (e.g., 'cp037', 'cp1047', 'cp500') that precisely matches the source data's encoding when decoding bytes. Consider using the `errors` parameter (e.g., `'ignore'`, `'replace'`) if some characters are expected to be un-decodable or if you want to handle them gracefully: `ebcdic_bytes.decode('cp037', errors='replace')`.Review the input string for characters not present in the target EBCDIC codepage. Use the `errors` parameter during encoding to handle unencodable characters (e.g., `'ignore'`, `'replace'`, `'xmlcharrefreplace'`, or `'backslashreplace'`). For example: `python_string.encode('cp037', errors='replace')`.No dependency data recorded yet.