Created
September 11, 2013 21:01
-
-
Save glamp/6529725 to your computer and use it in GitHub Desktop.
This file contains hidden or 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(column_name): | |
""" | |
converts a string that is camelCase into snake_case | |
Example: | |
print camel_to_snake("javaLovesCamelCase") | |
> java_loves_camel_case | |
See Also: | |
http://stackoverflow.com/questions/1175208/elegant-python-function-to-convert-camelcase-to-camel-case | |
""" | |
s1 = re.sub('(.)([A-Z][a-z]+)', r'\1_\2', column_name) | |
return re.sub('([a-z0-9])([A-Z])', r'\1_\2', s1).lower() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment