Skip to content

Instantly share code, notes, and snippets.

@snim2
Created September 26, 2010 15:23
Show Gist options
  • Select an option

  • Save snim2/598017 to your computer and use it in GitHub Desktop.

Select an option

Save snim2/598017 to your computer and use it in GitHub Desktop.
def intellisplit(base_string):
"""Intelligently split and capitalise a string.
Turns variable names which may be underscored or
in CamelCase into something human readable.
e.g. foo_bar should become Foo bar
fooBar should become Foo bar
etc.
"""
donkey = base_string[0] # A donkey is not a camel
for letter in base_string[1:]:
if letter.isupper():
donkey += '_' + letter.lower()
else:
donkey += letter
words = donkey.split('_')
return ' '.join([words[0].title()] + map(lambda w: w.lower(), words[1:]))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment