Created
February 27, 2018 20:51
-
-
Save rlabbe/2e3df888b66500cb741710de7d00c962 to your computer and use it in GitHub Desktop.
camel case to snake case
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(name): | |
s1 = re.sub('(.)([A-Z][a-z]+)', r'\1_\2', name) | |
return re.sub('([a-z0-9])([A-Z])', r'\1_\2', s1).lower() | |
# convert comma separated csv header | |
keys = header.split(',') | |
keys = [camel_to_snake(k) for k in keys] | |
header = ','.join(keys) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment