以任何方式将python脚本的输出直接传输到.txt文件中(any way to transfer output of a python script directly into a .txt fil

编程入门 行业动态 更新时间:2024-10-18 20:32:18
以任何方式将python脚本的输出直接传输到.txt文件中(any way to transfer output of a python script directly into a .txt file)

嗨,我觉得调用函数来验证数字的首要性是特别繁琐的,特别是当我处理的数字大于数百万时。 我想知道是否有一种方法可以生成高达十亿的素数,并将输出直接复制到.txt文件中,即使在python中处理素数时也是如此? 谢谢。

Hi I find it tedious to call the function to verify primacy of numbers especially when I am dealing with large numbers > few millions. I would like to know if there is a way I can generate primes up to say a billion and copy the output into a .txt file directly even as the primes are being crunched in python? thank you.

最满意答案

假设unix:

python myprogram.py > outputfile.txt

是标准输出重定向。 或者你可以写出一个文件:

def writeout(output): f = open('file.txt', 'w') f.write(output) f.close()

Assuming unix:

python myprogram.py > outputfile.txt

Is the standard output redirection. Or you can write out to a file:

def writeout(output): f = open('file.txt', 'w') f.write(output) f.close()

更多推荐

本文发布于:2023-07-26 00:22:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1268382.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:脚本   方式   文件   script   python

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!