Skip to content

Commit 74deee9

Browse files
author
Kareem Zidane
authored
Merge pull request #146 from cs50/input
replaces sys.stdin.readline with input
2 parents c4bb169 + 0cdfd92 commit 74deee9

File tree

1 file changed

+5
-11
lines changed

1 file changed

+5
-11
lines changed

src/cs50/cs50.py

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -133,17 +133,11 @@ def get_string(prompt):
133133
Read a line of text from standard input and return it as a string,
134134
sans trailing line ending. Supports CR (\r), LF (\n), and CRLF (\r\n)
135135
as line endings. If user inputs only a line ending, returns "", not None.
136-
Returns None upon error or no input whatsoever (i.e., just EOF). Exits
137-
from Python altogether on SIGINT.
136+
Returns None upon error or no input whatsoever (i.e., just EOF).
138137
"""
138+
if type(prompt) is not str:
139+
raise TypeError("prompt must be of type str")
139140
try:
140-
if prompt is not None:
141-
print(prompt, end="")
142-
s = sys.stdin.readline()
143-
if not s:
144-
return None
145-
return re.sub(r"(?:\r|\r\n|\n)$", "", s)
146-
except KeyboardInterrupt:
147-
sys.exit("")
148-
except ValueError:
141+
return input(prompt)
142+
except EOFError:
149143
return None

0 commit comments

Comments
 (0)