views:

52

answers:

2

my programme gives me very large results containg huge number of symbols,numbers.so that 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?

+3  A: 

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)
The MYYN
But this doesnt work when result is in form of list
If you know where to edit your python file, you probable also know, how to turn an array into a string? Anyway, edited my entry to reflect the possibility of `results` being a list.
The MYYN
+1  A: 

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()
Daniel Pryden