Skip to content Skip to sidebar Skip to footer

Descriptor 'join' Requires A 'unicode' Object But Received A 'str'

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

Solution 1:

The code seems to introduce unnecessary complexity, but you can do it like that:

#from 'foo_bar' to 'FooBar'
def lower_case_underscore_to_camel_case(self, string):
  printstring
  class_ = string.__class__
  return class_.join(class_('.'), map(class_.capitalize, string.split('_')))

And you could actually shorten the last line to be:

return class_('.').join(map(class_.capitalize, string.split('_')))

Also, judging from the code, you will receive something like "Foo.Bar" (notice a dot) from "foo_bar".

Post a Comment for "Descriptor 'join' Requires A 'unicode' Object But Received A 'str'"