开发者

can i store result directly as .txt file without getting displayed on GUI in python?

my programme gives me very large results containg huge number of symbols,numbers.so t开发者_如何学Pythonhat GUI often becomes 'non responding'.also takes so much time to display result.is there any way to store result as .txt file without getting displayed on GUI?


Sorry for being a little unspecific, but that's what I get out of your question.

 # results will contain your large dataset ...
 handle = open("filename.txt", "w")
 handle.write(results)
 handle.close()

Or:

 with open("filename.txt", "w") as f:
     f.write(results)

In case your results happen to be an iterable:

 # results will contain your large dataset ...
 handle = open("filename.txt", "w")
 handle.write(''.join(results)) # a little ugly, though
 handle.close()

Or:

 with open("filename.txt", "w") as f:
     for item in results:
         f.write(item)


Yes.

with open("filename.txt", "w") as f:
    for result_datum in get_my_results():
        f.write(result_datum)

Or if you need to use print for some reason:

f = open("filename.txt", "w")
_saved_stdout = sys.stdout
try:
    sys.stdout = f
    doMyCalculation()
finally:
    sys.stdout = _saved_stdout
    f.close()
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜