[pypy-dev] What's wrong with >>> open(?xxx?, ?w?).write(?stuff?) ?
donny.viszneki at gmail.com
Fri Aug 20 12:23:26 CEST 2010
Armin: Sakesun used "del f" and it appears you did not. In Python
IIRC, an explicit call to del should kick off the finalizer to flush
and close the file!
open('x', 'w').write('hello') alone does not imply the file instance
(return value of open()) has been finalized because the garbage
collector may not have hit it yet.
Jython and IronPython are pretty much guaranteed to behave differently
under a wide variety of circumstances when it comes to the garbage
collector. Do not rely on the garbage collector for program semantics!
Because Sakesun has used "del f" it should be quite a concern that the
file has not been finalized properly!
On Fri, Aug 20, 2010 at 5:57 AM, Armin Rigo <arigo at tunes.org> wrote:
> Hi Sakesun,
> On Thu, Aug 19, 2010 at 11:25:42AM +0700, sakesun roykiatisak wrote:
>> >>> f = open('xxx', 'w')
>> >>> f.write('stuff')
>> >>> del f
>> Also, I've tried that with both Jython and IronPython and they all work
> I guess that you didn't try exactly the same thing. If I do:
> arigo at tannit ~ $ jython
> Jython 2.2.1 on java1.6.0_20
> Type "copyright", "credits" or "license" for more information.
> >>> open('x', 'w').write('hello')
> Then "cat x" in another terminal shows an empty file. The file "x" is
> only filled when I exit Jython. It is exactly the same behavior as I
> get on PyPy. Maybe I missed something, and there is a different way to
> do things such that it works on Jython but not on PyPy; if so, can you
> describe it more precisely? Thanks!
> A bientot,
> pypy-dev at codespeak.net
More information about the Pypy-dev