Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reading stdin in Spyder

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.

like image 716
user61034 Avatar asked Oct 10 '17 15:10

user61034


People also ask

What is stdin read?

stdin. read() method accepts a line as the input from the user until a special character like Enter Key and followed by Ctrl + D and then stores the input as the string.

Is stdin faster than input Python?

stdin. readline() is the fastest one when reading strings and input() when reading integers.


Video Answer


1 Answers

(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).

like image 151
Carlos Cordoba Avatar answered Nov 15 '22 09:11

Carlos Cordoba