Code adapted from here:
#from 'foo_bar' to 'Foo.Bar'
def lower_case_underscore_to_camel_case(self, string):
print string
class_ = string.__class__
return class_.join('.', map(class_.capitalize, string.split('_')))
Output:
client_area
TypeError: descriptor 'join' requires a 'unicode' object but received a 'str'
Especially disappointing since the source code states:
“””Convert string or unicode from lower-case underscore to camel-case”””
How to fix this?
Easy fix:
return str.join('.', map(class_.capitalize, string.split('_')))
Could anyone explain me the overall process?
The code seems to introduce unnecessary complexity, but you can do it like that:
And you could actually shorten the last line to be:
Also, judging from the code, you will receive something like “
Foo.Bar” (notice a dot) from “foo_bar“.