python3 str或bytes转换函数

mac2022-06-30  19

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

 

 

 

  

转载于:https://www.cnblogs.com/chengd/p/7491041.html

相关资源:Python3中bytes类型转换为str类型
最新回复(0)