gpt4 book ai didi

python - Jupyter 笔记本输入字段出现在错误的位置

转载 作者:行者123 更新时间:2023-12-01 02:30:16 25 4
gpt4 key购买 nike

在 Jupyter 笔记本中,我运行以下命令

print("The input field should appear below this line")
input()

我希望获得文本行,后跟输入字段。但有时我会得到相反的结果。如何强制它以正确的顺序出现?

最佳答案

print 函数将文本发送到系统的标准输出缓冲区。然后系统决定何时将缓冲区中的内容推送到前端。在您的情况下,这种情况偶尔会在 input 请求之后发生。您可以通过将 flush=True 添加为 print 函数的关键字参数来告诉系统“立即推送输出”。 p>

print("The input field should appear below this line", flush=True)
input()

此外,您还可以让您的输入打印一行文本。

input("The input field appear next to this line: ")

关于python - Jupyter 笔记本输入字段出现在错误的位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46909370/

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