简体   繁体   English

如何在 linux 中使用 python 在 vscode 中调试标准输入?

[英]How do I debug stdin in vscode using python in linux?

I am using VS Code on Ubuntu and I wrote this simple python script to read user input from the terminal, just to learn about standard input modes.我在 Ubuntu 上使用 VS Code,我编写了这个简单的 python 脚本来从终端读取用户输入,只是为了了解标准输入模式。 I want to demonstrate the value in sys.stdin when the standard input mode is set to 'cbreak' (using tty.setcbreak(sys.stdin.fileno()) ).当标准输入模式设置为“cbreak”(使用tty.setcbreak(sys.stdin.fileno()) )时,我想演示 sys.stdin 中的值。

I added sys.stdin.read(), sys.stdin.readline() and sys.stdin.readlines() to the watch variables but I am not getting anything.我将 sys.stdin.read()、sys.stdin.readline() 和 sys.stdin.readlines() 添加到监视变量中,但我什么也没得到。 The variables show 'not available' and the local variables on the top left show loading.变量显示“不可用”,左上角的局部变量显示正在加载。

How can I watch standard input?如何观看标准输入?

Here is the script and a screenshot below.下面是脚本和屏幕截图。

import sys,tty,termios

old_attr=termios.tcgetattr(sys.stdin)
tty.setcbreak(sys.stdin.fileno())
input()
print("Exit")
termios.tcsetattr(sys.stdin,termios.TCSADRAIN,old_attr)

截屏

You add a breakpoint in line7.您在第 7 行添加了一个断点。

You coulde press F5 to continue so that you can get the output in the terminal.您可以按 F5 继续,这样您就可以在终端中获得 output。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM