问题
I have some programming assignments which read input data from stdin like this:
text = sys.stdin.readline().strip()
I am using Spyder as my development environment, and am not able to find a way to give the stdin. So, I added a -infile option to the code, and am reading from the file.
However, when submitting, I need to revert back to reading the stdin. How can I read stdin in the first place? I know how to do this from linux command line, but for now have to use windows.
回答1:
(Spyder maintainer here) The code you posted only works to read text when you run it in a system terminal (i.e. bash or cmd.exe).
It doesn't work in Spyder because its terminals are implemented in a different technology (PyQt vs. readline).
来源:https://stackoverflow.com/questions/46671039/reading-stdin-in-spyder