how to save the output of a cell in iPython notebook?

前端 未结 1 1874
礼貌的吻别
礼貌的吻别 2020-12-14 16:30

I would like to be able to save the TEXT output of an iPython notebook cell into a file on disk.

I have 2 additional requirements/requests:

相关标签:
1条回答
  • 2020-12-14 16:53

    You have a typo, missing d in cap.stout. It should be cap.stdout I tested the following and it worked fine. cap.show() also printed "stuff" and re-running the cell overwrote the file.

    %%capture cap --no-stderr
    print 'stuff'
    with open('output.txt', 'w') as f:
        f.write(cap.stdout)
    
    0 讨论(0)
提交回复
热议问题