MCPcopy Index your code
hub / github.com/python/cpython / current_line

Method current_line

Tools/gdb/libpython.py:1222–1243  ·  view source on GitHub ↗

Get the text of the current source line as a string, with a trailing newline character

(self)

Source from the content-addressed store, hash-verified

1220 return None
1221
1222 def current_line(self):
1223 '''Get the text of the current source line as a string, with a trailing
1224 newline character'''
1225 if self.is_optimized_out():
1226 return FRAME_INFO_OPTIMIZED_OUT
1227
1228 lineno = self.current_line_num()
1229 if lineno is None:
1230 return '(failed to get frame line number)'
1231
1232 filename = self.filename()
1233 try:
1234 with open(os.fsencode(filename), 'r', encoding="utf-8") as fp:
1235 lines = fp.readlines()
1236 except IOError:
1237 return None
1238
1239 try:
1240 # Convert from 1-based current_line_num to 0-based list offset
1241 return lines[lineno - 1]
1242 except IndexError:
1243 return None
1244
1245 def write_repr(self, out, visited):
1246 if self.is_optimized_out():

Callers 2

current_lineMethod · 0.45

Calls 5

is_optimized_outMethod · 0.95
current_line_numMethod · 0.95
filenameMethod · 0.95
openFunction · 0.50
readlinesMethod · 0.45

Tested by

no test coverage detected