Likelihood of IOError during print vs. write

Posted by jkasnicki on Stack Overflow See other posts from Stack Overflow or by jkasnicki
Published on 2010-05-04T06:00:32Z Indexed on 2010/05/04 6:08 UTC
Read the original article Hit count: 176

Filed under:
|
|

I recently encountered an IOError writing to a file on NFS. There wasn't a disk space or permission issue, so I assume this was just a network hiccup. The obvious solution is to wrap the write in a try-except, but I was curious whether the implementation of print and write in Python make either of the following more or less likely to raise IOError:

f_print = open('print.txt', 'w')
print >>f_print, 'test_print'
f_print.close()

vs.

f_write = open('write.txt', 'w')
f_write.write('test_write\n')
f_write.close()

(If it matters, specifically in Python 2.4 on Linux).

© Stack Overflow or respective owner

Related posts about python

Related posts about exception