
- Python Basic Tutorial
- Python - Home
- Python - Overview
- Python - Environment Setup
- Python - Basic Syntax
- Python - Comments
- Python - Variables
- Python - Data Types
- Python - Operators
- Python - Decision Making
- Python - Loops
- Python - Numbers
- Python - Strings
- Python - Lists
- Python - Tuples
- Python - Dictionary
- Python - Date & Time
- Python - Functions
- Python - Modules
- Python - Files I/O
- Python - Exceptions
Encode and decode binhex4 files using Python (binhex)
The binhex module encodes and decodes files in binhex4 format. This format is used in the representation of Macintosh files in ASCII. Only the data fork is handled.
The binhex module defines the following functions −
binhex.binhex(input, output): Convert a binary file with filename input to binhex file output. The output parameter can either be a filename or a file-like object (any object supporting a write() and close() method).
binhex.hexbin(input, output): Decode a binhex file input. input may be a filename or a file-like object supporting read() and close() methods. The resulting file is written to a file named output unless the argument is None in which case the output filename is read from the binhex file.
import binhex import sys infile = "file.txt" binhex.binhex(infile, 'test.hqx')
(This file must be converted with BinHex 4.0)
:#'CTE'8ZG(Kd!&4&@&3rN!3!N!8G!*!%Ql&6D@e`E'8JDA-JBQ9dG'9b)(4SB@i JBfpYF'aPH-bk!!!:
To convert hex in binary format
import binhex import sys infile = "test.hqx" binhex.binhex(infile, 'test.txt')
- Related Articles
- Encode and decode uuencode files using Python
- Encode and decode XDR data using Python xdrlib
- Encode and decode MIME quoted-printable data using Python
- Arduino – base64 encode and decode
- Encode and Decode Strings in C++
- What is the difference between encode/decode in Python?
- How to encode and decode URl in typescript?
- How to Encode and Decode JSON and Lua Programming?
- How to encode and decode a URL in JavaScript?
- Generate temporary files and directories using Python
- Read and write WAV files using Python (wave)
- Decode Ways in Python
- Rename multiple files using Python
- How to encode multiple strings that have the same length using Tensorflow and Python?
- Read and write AIFF and AIFC files using Python (aifc)
