如何在python文本文件中编写ipython命令的输出? [英] How to write the output of ipython command in python text file?
本文介绍了如何在python文本文件中编写ipython命令的输出?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想将以下ipython命令的输出捕获到一个文件中:
命令和输出区域如下:
I want to capture the output of the following ipython command into a file: commands and outputs areas follows:
`decoder.get_hyp()`
WARNING: "ngram_search.c", line 1000: </s> not found in last frame, using ++NOISE++ instead
INFO: ngram_search.c(1046): lattice start node <s>.0 end node ++NOISE++.171
INFO: ps_lattice.c(1225): Normalizer P(O) = alpha(++NOISE++:171:185) = -2003082
INFO: ps_lattice.c(1263): Joint P(O,S) = -2036704 P(S|O) = -33622
Out[7]: ('WELCOME TO MY TALK', '000000000', -36704586)
我想在我的文件中仅捕获欢迎来到我的谈话部分。
I want to capture only the part "wellcome to my talk" into my file.
推荐答案
使用IPython魔术函数 store
Use the IPython magic function store
%store foo >> a.txt # Append value of foo to file a.txt
这篇关于如何在python文本文件中编写ipython命令的输出?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文