我通过Stata学习了数据操纵和分析,并使用log命令记录了所有写入的命令和生成的输出。这样做可以重现我的发现,检查以前的结果并与其他人共享pdf或txt。在Python中使用什么?如果我使用Python Jupyter Notebook或Spyder有区别吗?
执行所需操作的方法是使用%logstart命令,如下所述:
%logstart
记录IPython输出?
有以下-o选项%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
请注意,重新启动后,“输出记录”现在为“真”。