Created
September 26, 2010 15:23
-
-
Save snim2/598017 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 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