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 in Python by ana1504.k
• 7,870 points
16 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 by SDeb
• 13,160 points

Related Questions In Python

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
• 56,200 points
19 views
0 votes
0 answers

how can i read from a stdin?

can you give an example? READ MORE

Apr 1 in Python by Waseem
• 4,160 points
9 views
+3 votes
5 answers

How to read multiple data files in python

Firstly we will import pandas to read ...READ MORE

answered Apr 6, 2018 in Python by DeepCoder786
• 1,700 points
1,340 views
+1 vote
4 answers

Comparing input functions

In Python raw_input() allows you to enter ...READ MORE

answered Oct 18, 2018 in Python by fuji
35 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
• 56,200 points
276 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
• 56,200 points
31 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
• 56,200 points
44 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
• 56,200 points
36 views
0 votes
1 answer

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

with open(fname) as f:     content = f.readlines() # you ...READ MORE

answered Oct 9, 2018 in Python by SDeb
• 13,160 points
105 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,160 points
24 views