input vs sys stdin read

0 votes
import sys
s1 = input()
s2 = sys.stdin.read(1)

#type "s" for example

s1 == "s" #False
s2 == "s" #True

How can I make input() to work properly? I tried to encode/decode s1, but it doesn't work.

Jul 23, 2019 in Python by ana1504.k
• 7,910 points
4,774 views

1 answer to this question.

0 votes
If you're on Windows, you'll notice that the result of input() when you type an 's' and Enter is "s\r". Strip all trailing whitespace from the result and you'll be fine.
answered Jul 23, 2019 by SDeb
• 13,300 points

Related Questions In Python

+1 vote
1 answer

How 2 compare words read by sys.stdin.sys() in Python 3?

Hi Alex, You could use something like this: import ...READ MORE

answered Jan 20, 2020 in Python by Yamini
767 views
0 votes
1 answer

Read input of integers in Python

In the upper version of Python 3.x, raw_input was ...READ MORE

answered Oct 26, 2018 in Python by Priyaj
• 58,140 points
233 views
0 votes
0 answers

how can i read from a stdin?

can you give an example? READ MORE

Apr 1, 2019 in Python by Waseem
• 4,540 points
243 views
0 votes
1 answer

How to prompt for user input and read command-line arguments?

To read user input you can try the cmd module for ...READ MORE

answered Jan 5 in Python by Gitika
• 65,950 points
412 views
0 votes
1 answer

Crawling after login in Python

You missed a few login data forms, ...READ MORE

answered Sep 7, 2018 in Python by Priyaj
• 58,140 points
960 views
0 votes
1 answer

Crawling after login in Python

You missed a few login data forms, ...READ MORE

answered Sep 14, 2018 in Python by Priyaj
• 58,140 points
260 views
0 votes
1 answer

“stub” __objclass__ in a Python class how to implement it?

You want to avoid interfering with this ...READ MORE

answered Sep 27, 2018 in Python by Priyaj
• 58,140 points
398 views
+1 vote
1 answer

How is raw_input() and input() in python3.x?

raw_input() was renamed to input() so now input() returns the exact string ...READ MORE

answered Oct 30, 2018 in Python by Priyaj
• 58,140 points
290 views
0 votes
2 answers

In Python, how do I read a file line-by-line into a list?

readline function help to  read line in ...READ MORE

answered Jun 21, 2020 in Python by sahil
• 560 points
607 views
0 votes
1 answer

When to use file vs open in Python?

File() has been removed since Python 3.0 ...READ MORE

answered Oct 30, 2018 in Python by SDeb
• 13,300 points
302 views