gpt4 book ai didi

python - Python iter() 中的 b'' sentinel 是什么意思?

转载 作者:太空狗 更新时间:2023-10-30 02:21:33 25 4
gpt4 key购买 nike

假设我有一个返回一堆行的进程,我想遍历这些行:

import subprocess

myCmd = ['foo', '--bar', '--baz']
myProcess = subprocess.Popen(myCmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
for myLine in iter(myProcess.stdout.readline, b''):
print myLine

iter() 的哨兵参数是什么?在这个例子中,我将值 b'' 传递给它?我想我自己理解 '' — 我停止在空行上迭代 — 但我不知道 b'' 是什么意思。

最佳答案

在 python3 中,字符串是字节文字。在 python 2 中被忽略。

关于python - Python iter() 中的 b'' sentinel 是什么意思?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15493981/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com