open() bug? or feature?
Martin v. Loewis
martin at v.loewis.de
Mon Aug 5 17:32:27 EDT 2002
"Adonis" <deltapigz at telocity.com> writes:
> i did this:
> >>> x = open('/tmp/test1.txt', 'w').write('hi!')
> >>> x
>
> the data is written, and the file is closed?
Is that a question, or a statement of fact?
Yes, the data is written, and the file is closed.
> is this a feature?
That the data is written is a feature. That x becomes None is also a
feature - x is the result of the write call, and write returns None.
That the file is closed is an implementation detail guaranteed for
CPython: since nobody references the file anymore, it is closed, and
the file object is released.
(notice that x does *not* reference the file object, as x gets the
result of the write call, not the result of the open call).
HTH,
Martin
More information about the Python-list
mailing list