open() bug? or feature?

Daniel Fackrell unlearned at
Mon Aug 5 17:36:27 EDT 2002

"Adonis" <deltapigz at> wrote in message
news:3d4eedb8$1_3 at nopics.sjc...
> i did this:
> >>> x = open('/tmp/test1.txt', 'w').write('hi!')
> >>> x
> the data is written, and the file is closed? is this a feature?
> or a bug?

It has been cast in both lights previously.  Seems to boil down to it being
undocumented, implementation-specific behavior.  There is nothing
guaranteeing that it works for any implementation, and Jython is known to
behave somewhat differently for such cases.

Note also that you are assigning x to the return value of write(), not the
file handle returned by open().

Daniel Fackrell (unlearned at
When we attempt the impossible, we can experience true growth.

More information about the Python-list mailing list