如何将 python 大结果导出到 txt 文件

how to export python large results to txt file

我有大量来自 python 的数据输出,我不能只将整个输出按 CtrlC 并按 CtrlV 到 txt 文件中。

[![enter image description here][1]][1]
    IOPub data rate exceeded.
    The notebook server will temporarily stop sending output
    to the client in order to avoid crashing it.
    To change this limit, set the config variable
    `--NotebookApp.iopub_data_rate_limit`.

    
    Current values:
    NotebookApp.iopub_data_rate_limit=1000000.0 (bytes/sec)
    NotebookApp.rate_limit_window=3.0 (secs)

So, I want to save it directly using queries. 

我尝试导入 sys 并写入 txt 文件但失败了。

有什么方法可以导出并保存 python 中的这个大型 txt 输出?

这是调整后更好地理解我的数据的图像print(giRaw)

这应该像下面这样简单:

with open(FILE_NAME, 'a') as the_file:
    the_file.write('<<your text here>>')

with open(FILE_NAME, 'a') as the_file:
    print("hi there", file=the_file)

如果您在程序的变量中包含文本,则可以使用以下代码片段。

# Assume your text is present in the variable "text"
text = 'blab blab ....'

# specify your file path
file_path = '/home/user/data.txt'

with open(file_path, 'w') as fp:
    fp.write(text)