Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python3
- # -*- coding: utf-8 -*-
- # Filename: bin2csv.py
- # Version: 1.0.1
- # Author: Jeoi Reqi
- """
- Description:
- This script converts a binary file (.bin) to a CSV file (.csv).
- It assumes that each line in the binary file represents a separate record, & it decodes each line from UTF-8 before writing it to the CSV file.
- Requirements:
- - Python 3.x
- - No additional external libraries are required.
- Usage:
- 1. Save this script as 'bin2csv.py'.
- 2. Ensure your binary file ('example.bin') is in the same directory as the script.
- 3. Run the script.
- 4. The converted CSV file ('bin2csv.csv') will be generated in the same directory.
- Note: Adjust the 'bin_filename' and 'csv_filename' variables in the script as needed.
- """
- import csv
- def bin_to_csv(bin_filename, csv_filename):
- with open(bin_filename, 'rb') as binfile, open(csv_filename, 'w', newline='') as csvfile:
- csvwriter = csv.writer(csvfile)
- for line in binfile:
- # Assuming each line in the binary file is a separate record
- csvwriter.writerow([line.decode('utf-8').strip()])
- if __name__ == "__main__":
- bin_filename = 'example.bin'
- csv_filename = 'bin2csv.csv'
- bin_to_csv(bin_filename, csv_filename)
- print(f"Converted '{bin_filename}' to '{csv_filename}'.")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement