M
MRAB
You could do:Fab86 said:Ok, I managed to import the correct error class (was in a non expected
place)
Just as I thought I was finished, I encountered a final problem. I am
running a while loop which is constantly adding search results to a
file, like this (print >> f, res.total_results_available). I have put
an exception in that if it times out, it simply tries again until its
finished. The problem is that the loop re-write all new results
continuing on from the previous searches. I would like to somehow
delete all in that file and start again.
I thought this could simply be achieved by putting f.close() in the
exception and then it re-writes it however I am getting this error:
Traceback (most recent call last):
File "/home/csunix/scs5fjnh/FYProj/Python/pYsearch-3.1/test9.py",
line 17, in <module>
print >> f, res.total_results_available
ValueError: I/O operation on closed file
Is there another way rather than closing the file? Is it possible to
delete all within the file?
f.seek(0)
f.truncate()
I hope you don't just discard all the results you've got so far and then
start from the beginning again.