Advertisement
Python253

to_kebab_case

May 23rd, 2024
591
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.87 KB | None | 0 0
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. # Filename: to_kebab_case.py
  4. # Version: 1.0.0
  5. # Author: Jeoi Reqi
  6.  
  7. """
  8. Description:
  9.    This script converts input text to Kebab Case, where spaces are replaced with hyphens ('-').
  10.    The converted text is then saved to a file named "converted_kebab_case.txt" in UTF-8 encoding.
  11.  
  12. Requirements:
  13.    - Python 3.x
  14.  
  15. Functions:
  16.    - to_kebab_case(text): Converts input text to Kebab Case.
  17.        Parameters:
  18.            text (str): The input text to be converted.
  19.        Returns:
  20.            str: The text converted to Kebab Case.
  21.  
  22. Usage:
  23.    Run the script and provide the text you want to convert when prompted.
  24.    The converted text will be saved to "converted_kebab_case.txt" in the same directory as the script.
  25.  
  26. Example Output:
  27.    Input Text: "This is a Test of Case Converting"
  28.    
  29.    Converted Text Has Been Saved To: 'converted_kebab_case.txt'.
  30.    
  31.    Converted Text:
  32.            this-is-a-test-of-case-converting
  33. """
  34.  
  35. def to_kebab_case(text):
  36.     """
  37.    Converts input text to Kebab Case.
  38.    
  39.    Parameters:
  40.        text (str): The input text to be converted.
  41.    
  42.    Returns:
  43.        str: The text converted to Kebab Case.
  44.    """
  45.     return '-'.join(text.lower().split())
  46.  
  47. def main():
  48.     """
  49.    Main function of the script.
  50.    
  51.    Prompts the user to input text, converts it to Kebab Case,
  52.    and saves the converted text to a file named "converted_kebab_case.txt".
  53.    """
  54.     input_text = input("Enter the text you want to convert to Kebab Case: ")
  55.     kebab_case_text = to_kebab_case(input_text)
  56.  
  57.     with open("converted_kebab_case.txt", "w", encoding="utf-8") as file:
  58.         file.write(kebab_case_text)
  59.    
  60.     print(f"\nConverted Text Has Been Saved To: 'converted_kebab_case.txt'.\n\nConverted Text:\n\t\t{kebab_case_text}")
  61.  
  62. if __name__ == "__main__":
  63.     main()
  64.  
  65.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement