在Pycharm中设置“检查点”

时间:2017-03-20 16:11:09

标签: python debugging pycharm

我正在使用Python 2.7与Pycharm,我正在处理一个非常大的文本文件;它们总共大约3gb。

我需要对文件中的数据运行LDA,PoS标记和其他特征提取方法,但每次我测试我的代码时,它都必须从头开始读取文件并重新执行相同的过程。

这就是为什么我经常使用Jupyter,因为以前单元格中的所有数据/变量都保存在内存中。

有没有办法和Pycharm做类似的事情? 例如,假设我正在向do_some_feature_extraction()

添加功能
def do_some_feature_extraction(str_list):    
    # feature extraction 1   
    # feature extraction 2

str_list = []
with open("some_file.txt", "rb") as f_in:
     for line in f_in:
          str_list.append(line)

do_some_feature_extraction(str_list)

假设“特征提取1”出现错误,然后我修复了它。 然后我将再次运行代码,然后在“特征提取2”上会出现另一个错误。然后我将修复它并从头开始再次运行代码。

我可以在执行do_some_feature_extraction(str_list)之前设置某种检查点吗?

而不是这样做

1 个答案:

答案 0 :(得分:1)

点击代码的左侧...在行号旁边(或者如果关闭它们,则会显示行号)

enter image description here

应出现一个红点(这称为断点)......

enter image description here

现在以调试模式运行

enter image description here

当您到达断点时,可以单击控制台选项卡

enter image description here

然后单击交互式终端按钮(> _)直接使用程序的上下文

enter image description here