本来打算简简单单的去前缀的,没想到却碰瓷了。
1.中文的事情。不知道该怎么解决。
2.lstrip
网上随便找的函数,不好用。
Python 2.7.6 (default, Nov 10 2013, 19:24:18)
Type \"help\", \"copyright\", \"credits\" or \"license\" for more information.
>>> str1=\"helloabc\";
>>> str1.lstrip(\"hello\")
\'abc\'
>>> str1
\'helloabc\'
>>> a=\"不转不是中国人\"
>>> a.lstrip(\"不转\")
\'\\xca\\xc7\\xd6\\xd0\\xb9\\xfa\\xc8\\xcb\'
>>> a=\"不转不是中国人\"
>>> a.lstrip(\"不\")
\'\\xd7\\xaa\\xb2\\xbb\\xca\\xc7\\xd6\\xd0\\xb9\\xfa\\xc8\\xcb\'
>>> a.lstrip(\"不转\")
\'\\xca\\xc7\\xd6\\xd0\\xb9\\xfa\\xc8\\xcb\'
>>> a.lstrip(\"不转不\")
\'\\xca\\xc7\\xd6\\xd0\\xb9\\xfa\\xc8\\xcb\'
>>> b=\"abcabcabcdddddd\"
>>> b.lstrip(\"abc\")
\'dddddd\'
>>> c=\"abcabcabdddd\"
>>> c.listrip(\"abc\")
Traceback (most recent call last):
File \"\", line 1, in
AttributeError: \'str\' object has no attribute \'listrip\'
>>> c.lstrip(\"abc\")
\'dddd\'
>>> c.lstrip(\"cba\")
\'dddd\'
>>> d=\"abcabcabdabcddd\"
>>> d.lstrip(\"cba\")
\'dabcddd\'
>>> d=\"cbacbaabccabeeeee\"
>>> d.lstrip(\"cba\")
\'eeeee\'
>>> f=\"abcaabbcc\"
>>> f.lstrip(\"cba\")
\'\'
丰丰告诉我,中文字符前面加u就可以了,经测试,正确。
>>> a=u\"不转不是中国人\"
>>> a
u\'\\u4e0d\\u8f6c\\u4e0d\\u662f\\u4e2d\\u56fd\\u4eba\'
>>> print a.lstrip(u\"不转\")
是中国人
>>> print a.lstrip(u\"不转不\")
是中国人