A simple Python utility for converting PascalCase and CamelCase strings to snake_case. Perfect for developers working with different coding conventions.
The Case Converter Program helps standardize variable and function naming across different programming styles. It takes strings in PascalCase (where each word is capitalized) or CamelCase (where the first word is lowercase and subsequent words are capitalized) and converts them to snake_case (all lowercase with underscores between words).
- Converts both PascalCase and CamelCase to snake_case
- Preserves original characters except for case changes
- Handles strings with numbers correctly
- Simple command-line execution
- Easy to integrate into other Python projects
-
Clone the repository:
git clone https://github.com/fahadelahikhan/Case-Converter-Program.git cd Case-Converter-Program
-
Run the application:
python Case Converter Program.py
# Import the conversion function
from case_converter import convert_to_snake_case
# Convert a PascalCase string
pascal_string = "IAmAPascalCasedString"
snake_case = convert_to_snake_case(pascal_string)
print(snake_case) # Output: i_am_a_pascal_cased_string
# Convert a CamelCase string
camel_string = "iAmACamelCasedString"
snake_case = convert_to_snake_case(camel_string)
print(snake_case) # Output: i_am_a_camel_cased_string
# Converting a complex string with numbers
complex_string = "UserID123Generator"
converted = convert_to_snake_case(complex_string)
print(converted) # Output: user_id123_generator
# Converting a string with mixed cases
mixed_case = "HTTPResponseCode"
converted = convert_to_snake_case(mixed_case)
print(converted) # Output: http_response_code
The converter works by:
- Iterating through each character in the input string
- Checking if a character is uppercase
- When an uppercase character is found, converting it to lowercase and prefixing with an underscore
- Joining all characters together and removing any leading or trailing underscores
This approach effectively identifies word boundaries in PascalCase and CamelCase strings and inserts underscores accordingly.
Distributed under the MIT License. See LICENSE for details.
Note: This is a simple utility for educational and productivity purposes. For more complex naming convention conversions, consider using established libraries with additional features.