python3 str 或butes转换函数
2018-01-15 14:55
162 查看
str或bytes始终返回为str
#!/usr/bin/env python # -*- coding: utf-8 -*- def to_str(bytes_or_str): if isinstance(bytes_or_str, bytes): value = bytes_or_str.decode('utf-8') else: value = bytes_or_str return value #Instance of str
str或bytes始终返回为bytes
#!/usr/bin/env python # -*- coding: utf-8 -*- def to_str(bytes_or_str): if isinstance(bytes_or_str, str): value = bytes_or_str.encode('utf-8') else: value = bytes_or_str return value #Instance of bytes
相关文章推荐
- python3 str或bytes转换函数
- python(0)-Python中str操作的学习
- python编码(str和unicode)
- python中的字符数字之间的转换函数
- 人工智能之Python03 数字(Number)与字符串(str)
- python_str
- python笔记: 类中的__str__ 函数
- Python中str的format()方法
- python3 TypeError: a bytes-like object is required, not 'str'
- Python的str类
- python中的str()和repr()
- Python基础-定制类(str_iter_getItem_getattr_call)
- python 提示错误AttributeError: type object 'str' has no attribute '_name_'
- Python初学者错误:TypeError: unsupported operand type(s) for +: 'int' and 'str'
- python str与bytes之间的转换
- Python的repr和str有什么不同?
- 浅析Python 3 字符串中的 STR 和 Bytes 有什么区别
- python __str__ 和 __repr__
- python各种类型转换-int,str,char,float,ord,hex,oct等
- python3中的str和bytes