11from __future__ import print_function
22
33import inspect
4+ import os
45import re
56import sys
67
78from distutils .sysconfig import get_python_lib
89from os .path import abspath , join
910from termcolor import colored
10- from traceback import extract_tb , format_list , format_exception_only , format_exception
11+ from traceback import format_exception
1112
1213
13- class flushfile ():
14+ class _flushfile ():
1415 """
1516 Disable buffering for standard output and standard error.
1617
@@ -28,23 +29,11 @@ def write(self, x):
2829 self .f .flush ()
2930
3031
31- sys .stderr = flushfile (sys .stderr )
32- sys .stdout = flushfile (sys .stdout )
32+ sys .stderr = _flushfile (sys .stderr )
33+ sys .stdout = _flushfile (sys .stdout )
3334
3435
35- def eprint (* args , ** kwargs ):
36- """
37- Print an error message to standard error, prefixing it with
38- file name and line number from which method was called.
39- """
40- end = kwargs .get ("end" , "\n " )
41- sep = kwargs .get ("sep" , " " )
42- (filename , lineno ) = inspect .stack ()[1 ][1 :3 ]
43- print ("{}:{}: " .format (filename , lineno ), end = "" )
44- print (* args , end = end , file = sys .stderr , sep = sep )
45-
46-
47- def formatException (type , value , tb ):
36+ def _formatException (type , value , tb ):
4837 """
4938 Format traceback, darkening entries from global site-packages directories
5039 and user-specific site-packages directory.
@@ -67,28 +56,18 @@ def formatException(type, value, tb):
6756 return "" .join (lines ).rstrip ()
6857
6958
70- sys .excepthook = lambda type , value , tb : print (formatException (type , value , tb ), file = sys .stderr )
59+ sys .excepthook = lambda type , value , tb : print (_formatException (type , value , tb ), file = sys .stderr )
7160
7261
73- def get_char (prompt = None ):
74- """
75- Read a line of text from standard input and return the equivalent char;
76- if text is not a single char, user is prompted to retry. If line can't
77- be read, return None.
78- """
79- while True :
80- s = get_string (prompt )
81- if s is None :
82- return None
83- if len (s ) == 1 :
84- return s [0 ]
62+ def eprint (* args , ** kwargs ):
63+ raise RuntimeError ("The CS50 Library for Python no longer supports eprint, but you can use print instead!" )
8564
86- # Temporarily here for backwards compatibility
87- if prompt is None :
88- print ("Retry: " , end = "" )
8965
66+ def get_char (prompt ):
67+ raise RuntimeError ("The CS50 Library for Python no longer supports get_char, but you can use get_string instead!" )
9068
91- def get_float (prompt = None ):
69+
70+ def get_float (prompt ):
9271 """
9372 Read a line of text from standard input and return the equivalent float
9473 as precisely as possible; if text does not represent a double, user is
@@ -104,12 +83,8 @@ def get_float(prompt=None):
10483 except ValueError :
10584 pass
10685
107- # Temporarily here for backwards compatibility
108- if prompt is None :
109- print ("Retry: " , end = "" )
110-
11186
112- def get_int (prompt = None ):
87+ def get_int (prompt ):
11388 """
11489 Read a line of text from standard input and return the equivalent int;
11590 if text does not represent an int, user is prompted to retry. If line
@@ -121,40 +96,12 @@ def get_int(prompt=None):
12196 return None
12297 if re .search (r"^[+-]?\d+$" , s ):
12398 try :
124- i = int (s , 10 )
125- if type (i ) is int : # Could become long in Python 2
126- return i
99+ return int (s , 10 )
127100 except ValueError :
128101 pass
129102
130- # Temporarily here for backwards compatibility
131- if prompt is None :
132- print ("Retry: " , end = "" )
133-
134-
135- if sys .version_info .major != 3 :
136- def get_long (prompt = None ):
137- """
138- Read a line of text from standard input and return the equivalent long;
139- if text does not represent a long, user is prompted to retry. If line
140- can't be read, return None.
141- """
142- while True :
143- s = get_string (prompt )
144- if s is None :
145- return None
146- if re .search (r"^[+-]?\d+$" , s ):
147- try :
148- return long (s , 10 )
149- except ValueError :
150- pass
151-
152- # Temporarily here for backwards compatibility
153- if prompt is None :
154- print ("Retry: " , end = "" )
155-
156-
157- def get_string (prompt = None ):
103+
104+ def get_string (prompt ):
158105 """
159106 Read a line of text from standard input and return it as a string,
160107 sans trailing line ending. Supports CR (\r ), LF (\n ), and CRLF (\r \n )
0 commit comments