Skip to content

Instantly share code, notes, and snippets.

@bluven
Last active August 29, 2015 14:05
Show Gist options
  • Save bluven/a9600e9d68f6fa2e169a to your computer and use it in GitHub Desktop.
Save bluven/a9600e9d68f6fa2e169a to your computer and use it in GitHub Desktop.
turn camel case into snake case
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