On Jul 16, 6:35 pm, [EMAIL PROTECTED] wrote:
> Hello,
>
> I'm a Python beginner and I'm trying to open, write and close a file
> in a
> correct manner. I've RTFM, RTFS, and I've read this
> thread:http://groups.google.ca/group/comp.lang.python/browse_thread/thread/7...
>
> I still cannot figure out the semantic of file.close(). As far as I
> can
> tell it is undocumented.
It's documented. Not necessarily very well, but it's documented.
Type help(file.close) at the interactive prompt.
close(...)
close() -> None or (perhaps) an integer. Close the file.
Sets data attribute .closed to True. A closed file cannot be used
for
further I/O operations. close() may be called more than once
without
error. Some kinds of file objects (for example, opened by
popen())
may return an exit status upon closing.
> How do I ensure that the close() methods in my finally clause do not
> throw an exception?
def quiet_close(fp):
"""Close a file, silently ignoring errors."""
try:
fp.close()
except IOError:
pass
--
http://mail.python.org/mailman/listinfo/python-list