1
clino 2013-08-07 14:49:34 +08:00
你这是在考大家还是咨询怎么做?
|
3
qdvictory 2013-08-07 15:06:36 +08:00
str = 'UserName'
''.join(chr(i) if i >= 97 else '_'+chr(i+32) for i in [ord(x) for x in str])[1:] |
4
qdvictory 2013-08-07 15:16:51 +08:00
再加个开头不是大写的。。
str = 'UserName' prefix = '_' text = ''.join(chr(i) if i >= 97 else prefix+chr(i+32) for i in [ord(x) for x in str]) text[len(prefix):] if text.startswith(prefix) else text |
5
qdvictory 2013-08-07 15:36:08 +08:00 1
import re
str = 'UserName' r = re.compile(r'[A-Z][a-z]+') li = re.findall(r,str) '_'.join([x.lower() for x in li]) |