Anonymous file closing

Sergey Krushinsky lunarium at comail.ru
Sat Jun 12 21:58:50 CEST 2004


Donn Cave wrote:

>Well, we may be getting into a semantic tight spot here.  What does
>`depend on' mean?  I think a reasonable interpretation is that normal
>files may be opened and read as shown above without concern about using
>up file descriptors, holding files open and preventing them from being
>effectively deleted, etc.
>  
>
I think, I can figure an example of such 'dependance'. This code:
    open(filename, 'w').write('spam ' + open(filename, 'r').read())
does not save 'spam' plus the old file contents, as I expected firstly. 
The result is just 'spam'. At the other hand, using file handles we can 
make it work as expected.

Sergey







More information about the Python-list mailing list