Check if a file is closed

bruno at modulix onurb at xiludom.gro
Mon Jun 19 05:09:57 EDT 2006


camillo at rockit.it wrote:
> How to check if a file is closed?

>>> f = open('trashme.txt', 'w')
>>> f
<open file 'trashme.txt', mode 'w' at 0x2aaaaab66e40>
>>> dir(f)
['__class__', '__delattr__', '__doc__', '__getattribute__', '__hash__',
'__init__', '__iter__', '__new__', '__reduce__', '__reduce_ex__',
'__repr__', '__setattr__', '__str__', 'close', 'closed', 'encoding',
'fileno', 'flush', 'isatty', 'mode', 'name', 'newlines', 'next', 'read',
'readinto', 'readline', 'readlines', 'seek', 'softspace', 'tell',
'truncate', 'write', 'writelines', 'xreadlines']
>>> f.closed
False
>>> f.close()
>>> f.closed
True


-- 
bruno desthuilliers
python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in 'onurb at xiludom.gro'.split('@')])"



More information about the Python-list mailing list