Last active
August 29, 2015 14:05
-
-
Save bluven/a9600e9d68f6fa2e169a to your computer and use it in GitHub Desktop.
turn camel case into snake case
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def camel_to_snake(name): | |
# for example: _getHTTPResponseCodeTest123Lab | |
# after first sub, name is _getHTTP_ResponseCodeTest123Lab | |
name = re.sub('(.)([A-Z][a-z]+)', r'\1_\2', name) | |
# after second sub, name is _get_http_response_code_test123_lab | |
return re.sub('([a-z0-9])([A-Z])', r'\1_\2', name).lower() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment