【发布时间】:2016-09-29 19:59:29
【问题描述】:
在 Python 3 中,如果我有这样的字符串:
print(some_str)
产生这样的结果:
b'This is the content of my string.\r\n'
我知道这是一个字节文字。
是否有一个函数可用于确定该字符串是否为字节文字格式(相对于具有 Unicode 'u' 前缀)而无需首先解释?还是有另一种最佳实践来处理这个问题?我有一种情况,其中获取字节文字字符串的处理方式与使用 Unicode 不同。理论上是这样的:
if is_byte_literal(some_str):
// handle byte literal case
else:
// handle unicode case
【问题讨论】:
-
你没有有
some_str,你有some_bytes!
标签: python string python-3.x