Advertisement
Python253

to_pascal_case

May 23rd, 2024
636
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.00 KB | None | 0 0
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. # Filename: to_pascal_case.py
  4. # Version: 1.0.0
  5. # Author: Jeoi Reqi
  6.  
  7. """
  8. Description:
  9.    This script converts input text to Pascal Case, where each word starts with an uppercase letter and there are no spaces between words.
  10.    The converted text is then saved to a file named "converted_pascal_case.txt" in UTF-8 encoding.
  11.  
  12. Requirements:
  13.    - Python 3.x
  14.  
  15. Functions:
  16.    - to_pascal_case(text): Converts input text to Pascal Case.
  17.        Parameters:
  18.            text (str): The input text to be converted.
  19.        Returns:
  20.            str: The text converted to Pascal 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_pascal_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_pascal_case.txt'.
  30.    
  31.    Converted Text:
  32.            ThisIsATestOfCaseConverting
  33. """
  34.  
  35. def to_pascal_case(text):
  36.     """
  37.    Converts input text to Pascal Case.
  38.    
  39.    Parameters:
  40.        text (str): The input text to be converted.
  41.    
  42.    Returns:
  43.        str: The text converted to Pascal Case.
  44.    """
  45.     words = text.split()
  46.     pascal_case_words = [word.capitalize() for word in words]
  47.     return ''.join(pascal_case_words)
  48.  
  49. def main():
  50.     """
  51.    Main function of the script.
  52.    
  53.    Prompts the user to input text, converts it to Pascal Case,
  54.    and saves the converted text to a file named "converted_pascal_case.txt".
  55.    """
  56.     input_text = input("Enter the text you want to convert to Pascal Case: ")
  57.     pascal_case_text = to_pascal_case(input_text)
  58.  
  59.     with open("converted_pascal_case.txt", "w", encoding="utf-8") as file:
  60.         file.write(pascal_case_text)
  61.    
  62.     print(f"\nConverted Text Has Been Saved To: 'converted_pascal_case.txt'.\n\nConverted Text:\n\t\t{pascal_case_text}")
  63.  
  64. if __name__ == "__main__":
  65.     main()
  66.  
  67.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement