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 <[email protected]>wrote:
> If I understand correctly, PyPy will garbage collect (and close) the
> file object at an indeterminate time. That time could be as long as
> until the program exits. Because CPython uses reference counting, it
> closes the file immediately after the file object goes out of scope.
>
> Of course, I may be entirely wrong.
>
> -Aaron DeVore
>
> On Wed, Aug 18, 2010 at 9:25 PM, sakesun roykiatisak <[email protected]>
> wrote:
> > Hi,
> > I encountered this quite a few times when learning pypy from internet
> > resources:
> > the code like this
> >>>> open(’xxx’, ’w’).write(’stuff’)
> > This code is not working on pypy because it rely on CPython refcounting
> > behaviour.
> > I don't get it. Why ? I thought the code should be similar to storing
> the
> > file object in temporary variable like this
> >>>> f = open('xxx', 'w')
> >>>> f.write('stuff')
> >>>> del f
> > Also, I've tried that with both Jython and IronPython and they all work
> > fine.
> > Why does this cause problem to pypy ? Do I have to avoid writing code
> like
> > this in the future ?
> > _______________________________________________
> > [email protected]
> > http://codespeak.net/mailman/listinfo/pypy-dev
> >
>
_______________________________________________
[email protected]
http://codespeak.net/mailman/listinfo/pypy-dev