Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- # -*- coding: utf-8 -*-
- # Filename: to_snake_case.py
- # Version: 1.0.0
- # Author: Jeoi Reqi
- """
- Description:
- This script converts input text to Snake Case, where spaces are replaced with underscores ('_').
- The converted text is then saved to a file named "converted_snake_case.txt" in UTF-8 encoding.
- Requirements:
- - Python 3.x
- Functions:
- - to_snake_case(text): Converts input text to Snake Case.
- Parameters:
- text (str): The input text to be converted.
- Returns:
- str: The text converted to Snake Case.
- Usage:
- Run the script and provide the text you want to convert when prompted.
- The converted text will be saved to "converted_snake_case.txt" in the same directory as the script.
- Example Output:
- Input Text: "This is a Test of Case Converting"
- Converted Text Has Been Saved To: 'converted_snake_case.txt'.
- Converted Text:
- this_is_a_test_of_case_converting
- """
- def to_snake_case(text):
- """
- Converts input text to Snake Case.
- Parameters:
- text (str): The input text to be converted.
- Returns:
- str: The text converted to Snake Case.
- """
- return '_'.join(text.lower().split())
- def main():
- """
- Main function of the script.
- Prompts the user to input text, converts it to Snake Case,
- and saves the converted text to a file named "converted_snake_case.txt".
- """
- input_text = input("Enter the text you want to convert to Snake Case: ")
- snake_case_text = to_snake_case(input_text)
- with open("converted_snake_case.txt", "w", encoding="utf-8") as file:
- file.write(snake_case_text)
- print(f"\nConverted Text Has Been Saved To: 'converted_snake_case.txt'.\n\nConverted Text:\n\t\t{snake_case_text}")
- if __name__ == "__main__":
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement