#!/usr/bin/env python3 # -*- coding: utf-8 -*- # Filename: bin2txt.py # Version: 1.0.0 # Author: Jeoi Reqi """ Description: This script converts a binary file (.bin) to a text file (.txt). It reads the binary content, assuming each line in the binary file represents a separate record. The script decodes each line from UTF-8 and saves the data as a text file. Requirements: - Python 3.x Usage: 1. Save this script as 'bin2txt.py'. 2. Ensure your binary file ('example.bin') is in the same directory as the script. 3. Run the script. 4. The converted text file ('bin2txt.txt') will be generated in the same directory. Note: Adjust the 'bin_filename' and 'txt_filename' variables in the script as needed. """ def bin_to_txt(bin_filename, txt_filename): with open(bin_filename, 'rb') as binfile, open(txt_filename, 'w') as txtfile: for line in binfile: txtfile.write(line.decode('utf-8')) if __name__ == "__main__": bin_filename = 'example.bin' txt_filename = 'bin2txt.txt' bin_to_txt(bin_filename, txt_filename) print(f"Converted '{bin_filename}' to '{txt_filename}'.")