iPython magic %logstart选项-o不工作。

时间:2021-09-07 22:00:15

I'm trying to save to file my iPython's session commands and output logging to file. It seems like this should do it:

我正在尝试将iPython的会话命令和输出日志文件保存到文件中。似乎应该这样做:

%logstart -o -r -t mylog.txt

When I run this:

当我运行:

print 3+2
for i in range(10):
    print i

I'd expect the log file to look like:

我希望日志文件看起来是这样的:

print 3+2
5
for i in range(5):
    print i

0
1
2
3
4

But all I get is:

但我得到的只有:

%logstart -o -r -t mylog.txt
print 3+2
for i in range(10):
    print i
%logstop

What is it that I'm doing wrong?

我做错了什么?

1 个解决方案

#1


0  

The log does not record print statements, only the value of entered expressions. Thus, instead of printing, try having a statement return what you need. Notice below how the result of 2+3 is displayed, while the result of print(2+3) is not:

日志没有记录打印语句,只有输入表达式的值。因此,不要打印,试着用一个语句返回您所需要的。注意以下是如何显示2+3的结果,而print(2+3)的结果不是:

# IPython log file
2+3
#[Out]# 5
print(2+3)
get_ipython().magic('logstop')

#1


0  

The log does not record print statements, only the value of entered expressions. Thus, instead of printing, try having a statement return what you need. Notice below how the result of 2+3 is displayed, while the result of print(2+3) is not:

日志没有记录打印语句,只有输入表达式的值。因此,不要打印,试着用一个语句返回您所需要的。注意以下是如何显示2+3的结果,而print(2+3)的结果不是:

# IPython log file
2+3
#[Out]# 5
print(2+3)
get_ipython().magic('logstop')