IPython: redirecting output of a Python script to a file (like bash >)

后端 未结 7 2079
慢半拍i
慢半拍i 2020-12-01 03:50

I have a Python script that I want to run in IPython. I want to redirect (write) the output to a file, similar to:

python my_script.py > my_output.txt


        
相关标签:
7条回答
  • 2020-12-01 04:19

    Writing a script seemed overkill for me, as I just wanted something simple to look at a lot of text contained in a variable while working in IPython. This is what worked for me:

    %store VARIABLE >> file.txt (appends)
    %store VARIABLE > file.txt (overwrites)

    0 讨论(0)
提交回复
热议问题