以任何方式将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.txtIs 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()更多推荐
发布评论