Python 3.x Error:TypeError: a bytes-like object is required, not 'str'
来源:互联网 发布:婚纱网络销售好做吗 编辑:程序博客网 时间:2024/06/05 13:34
TypeError: a bytes-like object is required, not 'str'
问题分析
该问题主要是由于当前操作的字符串是bytes类型的字符串对象,并对该bytes类型的字符串对象进行按照str类型的操作。
如下面图所示,s 为bytes类型字符串对象。
当对s进行按照str类型的操作(split)时,会弹出一下错误提示。因为split函数传入的参数是str类型的字符串,而党鞭的s为bytes编码类型的字符串对象
解决方法
此时的解决办法是,将s转码成为str类型的或者是将对s进行str类型操作转化为对bytes类型的操作。
方法1:bytes-->str
方法2:对s进行str类型操作转化为对bytes类型的操作
由于split里面用到分解字符串中的是空格‘ ’,但是该‘ ’是按照str编码的,需要转化成为bytes类型的,然后再直接对s进行对bytes类型的操作。
str和bytes类型之间的常用转码方式:
1、str to bytes:(3种方式)
2、bytes to str (3种方式)
4 0
- Python 3.x Error:TypeError: a bytes-like object is required, not 'str'
- TypeError: a bytes-like object is required, not 'str'
- python3 TypeError: a bytes-like object is required, not 'str'
- python3 TypeError: a bytes-like object is required, not 'str'
- TypeError: a bytes-like object is required, not 'str'
- TypeError: a bytes-like object is required, not 'str'
- python 3.5: TypeError: a bytes-like object is required, not 'str' when writing to a file
- python socket send 函数 报错:TypeError: a bytes-like object is required, not 'str'
- python中Base64编码和解码:TypeError: a bytes-like object is required, not 'str'
- Error:a bytes-like object is required not str
- a bytes-like object is required,not 'str'
- Python中“a bytes-like object is required, not 'str'”的问题
- python3.5 模拟UDP客户端发送数据报文,报错:TypeError: a bytes-like object is required, not 'str'
- python3中,socket使用send函数时出现的错误:TypeError: a bytes-like object is required, not 'str'
- Python中3+版本运行2+版本程序出现TypeError: a bytes-like object is required, not 'str'之读取PDF中的图片
- 解决python3的pickle.load错误:a bytes-like object is required, not 'str'
- python3 套接字异常(a byte-like object is required not str)
- python mysql插入数据报错:TypeError: %d format: a number is required, not str
- 疑惑解答---Servlet服务器与Tomcat之间关系
- LeetCode 202. Happy Number
- hdu 5968 异或密码 2016ACM/CCPC合肥赛区现场赛H
- PIC单片机入门_汇编/混编/C编比较
- uva 1363 公式求和(优化)
- Python 3.x Error:TypeError: a bytes-like object is required, not 'str'
- hihoCoder1116Calc(线段树区间合并)
- Unreal Engine 4 入门教程 github README翻译
- B - Equal Sum Sets
- Android即时通讯工具的简单实现
- jQuery串行动画小案例
- Problem : [JSOI2007]建筑抢修
- hdu 5969 最大的位或 2016ACM/CCPC合肥赛区现场赛I
- 组织变革-时代发展的产物