简体   繁体   中英

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. I want to demonstrate the value in sys.stdin when the standard input mode is set to 'cbreak' (using tty.setcbreak(sys.stdin.fileno()) ).

I added sys.stdin.read(), sys.stdin.readline() and sys.stdin.readlines() to the watch variables but I am not getting anything. 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.

You coulde press F5 to continue so that you can get the output in the terminal.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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