Skip to content

Commit 5455ee4

Browse files
authoredMay 21, 2017
Merge pull request #16 from cs50/eprint
added eprint
2 parents bf2b82a + d9c9aba commit 5455ee4

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed
 

‎cs50/cs50.py

+12
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from __future__ import print_function
2+
import inspect
23
import re
34
import sys
45

@@ -20,6 +21,17 @@ def write(self, x):
2021
sys.stderr = flushfile(sys.stderr)
2122
sys.stdout = flushfile(sys.stdout)
2223

24+
def eprint(*args, **kwargs):
25+
"""
26+
Print an error message to standard error, prefixing it with
27+
file name and line number from which method was called.
28+
"""
29+
end = kwargs.get("end", "\n")
30+
sep = kwargs.get("sep", " ")
31+
(filename, lineno) = inspect.stack()[1][1:3]
32+
print("{}:{}: ".format(filename, lineno), end="")
33+
print(*args, end=end, file=sys.stderr, sep=sep)
34+
2335
def get_char(prompt=None):
2436
"""
2537
Read a line of text from standard input and return the equivalent char;

0 commit comments

Comments
 (0)
Please sign in to comment.