Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python3
- # -*- coding: utf-8 -*-
- # Filename: text2html.py
- # Version: 1.0.0
- # Author: Jeoi Reqi
- """
- Description:
- This script converts a text file (.txt) to an HTML file (.html).
- It wraps the text content in an HTML body with a paragraph tag.
- Requirements:
- - Python 3.x
- Usage:
- 1. Save this script as 'text2html.py'.
- 2. Ensure your text file ('example.txt') is in the same directory as the script.
- 3. Run the script using the command: 'python text2html.py'
- 4. The converted HTML file ('text2html.html') will be generated in the same directory.
- Note: Adjust the 'text_file' and 'html_file' variables in the script as needed.
- """
- def text_to_html(text_file, html_file):
- with open(text_file, 'r') as textfile:
- text_data = textfile.read()
- html_data = f'<html><body><p>{text_data}</p></body></html>'
- with open(html_file, 'w') as htmlfile:
- htmlfile.write(html_data)
- if __name__ == "__main__":
- # Set the filenames for the text and HTML files
- text_file = 'example.txt'
- html_file = 'text2html.html'
- # Convert the text to an HTML file
- text_to_html(text_file, html_file)
- print(f"Converted '{text_file}' to '{html_file}'.")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement