pysession.py 文件源码

python
阅读 24 收藏 0 点赞 0 评论 0

项目:pysession 作者: FallibleInc 项目源码 文件源码
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
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号