其中Python strip() 方法用于移除字符串头尾指定的字符
split()就是将一个字符串分裂成多个字符串组成的列表
>>> image ='1.jsp,2.jsp,3.jsp,4.jsp' >>> image_list = image.strip(',').split(',') >>> print image_list ['1.jsp', '2.jsp', '3.jsp', '4.jsp'] >>>
本博客转载而来:转载自:https://www.cnblogs.com/xuchunlin/p/6676288.html
本博客转载而来:转载自:http://www.cnblogs.com/kiddy/p/5143031.html
其中Python strip() 方法用于移除字符串头尾指定的字符
split()就是将一个字符串分裂成多个字符串组成的列表
>>> image ='1.jsp,2.jsp,3.jsp,4.jsp' >>> image_list = image.strip(',').split(',') >>> print image_list ['1.jsp', '2.jsp', '3.jsp', '4.jsp'] >>>
因为python的read和write方法的操作对象都是string。而操作二进制的时候会把string转换成list进行解析,解析后重新写入文件的时候,还得转换成string。
import string str = 'abcde' list = list(str) list ['a', 'b', 'c', 'd', 'e'] str 'abcde' str_convert = ''.join(list) str_convert 'abcde'