Advertisement
Python253

create_example_text

Mar 11th, 2024
585
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_text.py
  4. # Version: 1.0.0
  5. # Author: Jeoi Reqi
  6.  
  7. """
  8. Description:
  9. This script creates an example text file ('example.txt') with sample data.
  10.  
  11. Requirements:
  12. - Python 3.x
  13.  
  14. Usage:
  15. 1. Save this script as 'create_example_text.py'.
  16. 2. Run the script.
  17.  
  18. Note: Adjust the 'text_filename' variable in the script as needed.
  19. """
  20.  
  21. def create_example_text(filename):
  22.     # Example text data (you can customize this data)
  23.     text_data = """Hello, World!
  24. This is an example text file.
  25. Feel free to add more lines or customize the content."""
  26.  
  27.     # Write text data to the file
  28.     with open(filename, 'w') as textfile:
  29.         textfile.write(text_data)
  30.  
  31. if __name__ == "__main__":
  32.     # Set the filename for the example text file
  33.     text_filename = 'example.txt'
  34.    
  35.     # Create the example text file in the current working directory
  36.     create_example_text(text_filename)
  37.  
  38.     print(f"Example text file '{text_filename}' created in the current working directory.")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement