python3中split分割字符串出现错误 TypeError‘str’ does not support the buffer interface

来源:互联网 发布:win7 apache php 编辑:程序博客网 时间:2024/06/11 16:12

错误如下:

>>>a=b'http://10.0.0.29/live.4809rRZjegpA7mIG_20170314153417.flv\r\nhttp://10.0.0.29/live.4809rRZjegpA7mIG_20170314133057.flv\r\nhttp://10.0.0.29/live.4809rfeVuoW9ur6C_20170314210442.flv'>>> a.split("\r\n")Traceback (most recent call last):  File "<stdin>", line 1, in <module>TypeError: 'str' does not support the buffer interface

解决方法:

原因是Python3x的string类型与Python2x的类型不相同,在Python3x中需要将str编码。

>>> a.split(bytes("\r\n",'utf-8'))[b'http://10.0.0.29/live.4809rRZjegpA7mIG_20170314153417.flv', b'http://10.0.0.29/live.4809rRZjegpA7mIG_20170314133057.flv', b'http://10.0.0.29/live.4809rfeVuoW9ur6C_20170314210442.flv']

参考:http://aleeee.com/python23_str.html

0 0
原创粉丝点击