Re: [pypy-dev] What's wrong with >>> open(’xxx’, ’w’).write(’stuff’) ?

That's make sense. I've tried on both IronPython and Jython with: ipy -c "open(’xxx’, ’w’).write(’stuff’)" jython -c "open(’xxx’, ’w’).write(’stuff’)" When the interpreter terminate the file is closed. That's why it didn't cause any problem. Perhaps, I should always use "with" statement from now on.
with open('xxx', 'w') as f: f.write('stuff')
Thanks On Thu, Aug 19, 2010 at 11:40 AM, Aaron DeVore <aaron.devore@gmail.com>wrote:

On Thu, Aug 19, 2010 at 12:07 AM, sakesun roykiatisak <sakesun@gmail.com> wrote:
Since PyPy implements Python 2.5 at present you'll need to use `from __future__ import with_statement` to ues it. Alex -- "I disapprove of what you say, but I will defend to the death your right to say it." -- Voltaire "The people's good is the highest law." -- Cicero "Code can always be simpler than you think, but never as simple as you want" -- Me

A good resource I recently read on this is this entry in Raymond Chen's blog: http://blogs.msdn.com/b/oldnewthing/archive/2010/08/09/10047586.aspx Together with the following entry, which explains why the lifetime of the variable has nothing to do with the lifetime of the object, this should help you understand. You should consider automatically closing a file to be an implementation detail, even cpython may not respect such semantics in future. That is why the with statement was created. -- William Leslie

Thanks. Interestingly, this is not the first time I was suggested to pursue further reading with Raymond Chen's blog. http://www.mail-archive.com/users@lists.ironpython.com/msg05792.html <http://www.mail-archive.com/users@lists.ironpython.com/msg05792.html> :) On Thu, Aug 19, 2010 at 12:13 PM, William Leslie < william.leslie.ttg@gmail.com> wrote:

On Thu, Aug 19, 2010 at 12:07 AM, sakesun roykiatisak <sakesun@gmail.com> wrote:
Since PyPy implements Python 2.5 at present you'll need to use `from __future__ import with_statement` to ues it. Alex -- "I disapprove of what you say, but I will defend to the death your right to say it." -- Voltaire "The people's good is the highest law." -- Cicero "Code can always be simpler than you think, but never as simple as you want" -- Me

A good resource I recently read on this is this entry in Raymond Chen's blog: http://blogs.msdn.com/b/oldnewthing/archive/2010/08/09/10047586.aspx Together with the following entry, which explains why the lifetime of the variable has nothing to do with the lifetime of the object, this should help you understand. You should consider automatically closing a file to be an implementation detail, even cpython may not respect such semantics in future. That is why the with statement was created. -- William Leslie

Thanks. Interestingly, this is not the first time I was suggested to pursue further reading with Raymond Chen's blog. http://www.mail-archive.com/users@lists.ironpython.com/msg05792.html <http://www.mail-archive.com/users@lists.ironpython.com/msg05792.html> :) On Thu, Aug 19, 2010 at 12:13 PM, William Leslie < william.leslie.ttg@gmail.com> wrote:
participants (3)
-
Alex Gaynor
-
sakesun roykiatisak
-
William Leslie