Advertisement
Python253

create_example_bin

Mar 11th, 2024
528
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.04 KB | None | 0 0
  1. #!/usr/bin/env python3
  2. # -*- coding: utf-8 -*-
  3. # Filename: create_example_bin.py
  4. # Version: 1.0.0
  5. # Author: Jeoi Reqi
  6.  
  7. """
  8. Description:
  9. This script creates an example binary file ('example.bin') containing the binary data 'Hello, World!'.
  10.  
  11. Requirements:
  12. - Python 3.x
  13.  
  14. Usage:
  15. 1. Save this script as 'create_example_bin.py'.
  16. 2. Run the script.
  17.  
  18. Note: Adjust the 'example_filename' variable in the script as needed.
  19. """
  20. def create_example_bin(filename):
  21.     # Example binary data (Hello, World!)
  22.     binary_data = bytes([0x48, 0x65, 0x6C, 0x6C, 0x6F, 0x2C, 0x20, 0x57, 0x6F, 0x72, 0x6C, 0x64, 0x21])
  23.  
  24.     # Write binary data to the file
  25.     with open(filename, 'wb') as binfile:
  26.         binfile.write(binary_data)
  27.  
  28. if __name__ == "__main__":
  29.     # Set the filename for the example binary file
  30.     example_filename = 'example.bin'
  31.  
  32.     # Create the example binary file in the current working directory
  33.     create_example_bin(example_filename)
  34.  
  35.     print(f"Example binary file '{example_filename}' created in the current working directory.")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement