Log IPython output?

后端 未结 1 1858
长发绾君心
长发绾君心 2020-12-17 17:38

Is there any way to make IPython\'s logging capability include output as well as input?

This is what a log file looks like currently:

#!/usr/bin/en         


        
相关标签:
1条回答
  • 2020-12-17 17:40

    There's the -o option for %logstart:

    -o: log also IPython's output.  In this mode, all commands which
      generate an Out[NN] prompt are recorded to the logfile, right after
      their corresponding input line.  The output lines are always
      prepended with a '#[Out]# ' marker, so that the log remains valid
      Python code.
    

    ADDENDUM: If you are in an interactive ipython session for which logging has already been started, you must first stop logging and then restart:

    In [1]: %logstop
    
    In [2]: %logstart -o
    Activating auto-logging. Current session state plus future input saved.
    Filename       : ./ipython.py
    Mode           : backup
    Output logging : True
    Raw input log  : False
    Timestamping   : False
    State          : active
    

    Observe that, after the restart, "Output Logging" is now "True".

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