How can I simplify this conversion from underscore to camelcase in Python?

This one works except for leaving the first word as lowercase.

def convert(word):
    return ''.join(x.capitalize() or '_' for x in word.split('_'))

(I know this isn’t exactly what you asked for, and this thread is quite old, but since it’s quite prominent when searching for such conversions on Google I thought I’d add my solution in case it helps anyone else).

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)