记录IPython输出?
有没有办法使IPython的日志记录功能既包括输出又包括输入 这是当前日志文件的外观:记录IPython输出?,ipython,Ipython,有没有办法使IPython的日志记录功能既包括输出又包括输入 这是当前日志文件的外观: #!/usr/bin/env python # 2012-08-06.py # IPython automatic logging file # 12:02 # ================================= print "test" 我想再多看一行: #!/usr/bin/env python # 2012-08-06.py # IPython automatic loggi
#!/usr/bin/env python
# 2012-08-06.py
# IPython automatic logging file
# 12:02
# =================================
print "test"
我想再多看一行:
#!/usr/bin/env python
# 2012-08-06.py
# IPython automatic logging file
# 12:02
# =================================
print "test"
# test
(之所以使用#
是因为我认为这是防止破坏IPython的logplay
功能所必需的)
我想这是可能的使用IPython笔记本电脑,但至少有一台机器我需要它,我只限于IPython 0.10.2
编辑:我想知道如何自动设置,即在配置文件中。现在我的配置看起来像
from time import strftime
import os
logfilename = strftime('ipython_log_%Y-%m-%d')+".py"
logfilepath = "%s/%s" % (os.getcwd(),logfilename)
file_handle = open(logfilepath,'a')
file_handle.write('########################################################\n')
out_str = '# Started Logging At: '+ strftime('%Y-%m-%d %H:%M:%S\n')
file_handle.write(out_str)
file_handle.write('########################################################\n')
file_handle.close()
c.TerminalInteractiveShell.logappend = logfilepath
c.TerminalInteractiveShell.logstart = True
但是指定
c.TerminalInteractiveShell.log\u output=True似乎没有任何影响对于%logstart
,有-o
选项:
-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.
附录:如果您处于已启动日志记录的交互式ipython会话中,则必须先停止日志记录,然后重新启动:
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
请注意,重新启动后,“输出日志记录”现在为“True”。解决方案似乎在启动脚本中执行此操作,如下所述:(这是中提供的解决方案)这非常方便,但在我的示例中,它只打印已执行的代码,而不是实际的回溯。