我的头撞到墙上了。。。在
我想从python脚本中运行一个特定的cli命令,然后对它的输出进行regex。但我得到了以下错误:
"File "speedtestcork.py", line 18, in regex_speedtest
for line in data.split("\n"):
TypeError: Type str doesn't support the buffer API"
下面是我的简短代码:
^{pr2}$这应该很容易调试,但我找不到解决方案。在
使用了以下帖子,但仍然无法解析:
Regex woes with Subprocess output
提前谢谢你
保罗
在Python3中,^{} 返回}需要{}输入。在
bytes
,而{以下是更新版本:
我已经将}都有效。在
r
前缀改为rb
,它将字符串文本转换为字节文本,并将split("\n")
调用替换为splitlines
,因为这对str
和{更新:正如邓肯在评论中所指出的,在
split
调用中用"\n"
替换b"\n"
也同样有效。在相关问题 更多 >
编程相关推荐