def process_history():
"""Processes python shell history to an array of code lines"""
end_index = len(PySession.ipython_history) - 1 if PySession.is_ipython \
else readline.get_current_history_length()
lines_of_code = []
for i in range(PySession.start_index, end_index):
if i in PySession.wrong_code_lines:
continue
if PySession.is_ipython:
line = PySession.ipython_history[i]
else:
line = readline.get_history_item(i)
# remove 'exit' and PySession keywords from code
if line.strip() in ['PySession.local()',
'PySession.gist()',
'PySession.off()',
'exit',
'exit()']:
continue
lines_of_code.append(line)
if len(
lines_of_code) > 0 and lines_of_code[-1] != '\n': # adding extra last newline
lines_of_code.append('\n')
return lines_of_code
评论列表
文章目录