Advertisement
Python253

test_0bin_1bin

Mar 5th, 2024
291
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.29 KB | None | 0 0
  1. #!/usr/bin/env python3
  2. # -*- coding: utf-8 -*-
  3. # Filename: test_0bin_1bin.py
  4. # Author: Jeoi Reqi
  5.  
  6. """
  7. This Python script generates test data and creates 0.bin and 1.bin files in the current working directory.
  8.  
  9. Requirements:
  10. - Python 3
  11.  
  12. Description:
  13. The script creates two binary files, 0.bin and 1.bin, in the current working directory.
  14. It encodes test content into these files using UTF-8 encoding.
  15. The purpose is to provide sample input files for testing a binary file decoding script.
  16. The generated files contain simple text messages for demonstration purposes.
  17.  
  18. Usage:
  19. Run the script using a Python 3 interpreter. The generated 0.bin and 1.bin files will be saved in the same directory as the script.
  20.  
  21. """
  22.  
  23. def write_binary_file(file_name, content):
  24.     with open(file_name, 'wb') as binary_file:
  25.         binary_file.write(content.encode('utf-8'))
  26.  
  27. if __name__ == "__main__":
  28.     # Test content for 0.bin and 1.bin
  29.     test_content_0 = "This is a test for 0.bin file."
  30.     test_content_1 = "And this is a test for 1.bin file."
  31.  
  32.     # Write to 0.bin
  33.     write_binary_file('0.bin', test_content_0)
  34.     print(f'Test content for 0.bin written to 0.bin')
  35.  
  36.     # Write to 1.bin
  37.     write_binary_file('1.bin', test_content_1)
  38.     print(f'Test content for 1.bin written to 1.bin')
  39.  
  40.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement