Skip to content

Instantly share code, notes, and snippets.

@cldotdev
Created May 24, 2013 03:27
Show Gist options
  • Select an option

  • Save cldotdev/5641107 to your computer and use it in GitHub Desktop.

Select an option

Save cldotdev/5641107 to your computer and use it in GitHub Desktop.
Convert CamelCase to camel_case
# http://stackoverflow.com/questions/1175208/elegant-python-function-to-convert-camelcase-to-camel-case
def convert(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()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment