Skip to content

Commit 9f7dca1

Browse files
committedApr 29, 2017
added eprint
1 parent b83c6a5 commit 9f7dca1

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed
 

‎cs50/cs50.py

+10
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,15 @@ def write(self, x):
2021
sys.stderr = flushfile(sys.stderr)
2122
sys.stdout = flushfile(sys.stdout)
2223

24+
def eprint(*objects, end="\n", sep=" "):
25+
"""
26+
Print an error message to standard error, prefixing it with caller's
27+
file name and line number.
28+
"""
29+
(frame, filename, lineno, function, code_context, index) = inspect.stack()[1]
30+
print("{}:{}: ".format(filename, lineno), end="")
31+
print(*objects, end=end, file=sys.stderr, sep=sep)
32+
2333
def get_char():
2434
"""Read a line of text from standard input and return the equivalent char."""
2535
while True:

0 commit comments

Comments
 (0)
Please sign in to comment.