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

sakesun roykiatisak sakesun at gmail.com
Thu Aug 19 07:07:47 CEST 2010


A little problem is that, "with" statement is yet to work in pypy.

:)


On Thu, Aug 19, 2010 at 11:49 AM, sakesun roykiatisak <sakesun at gmail.com>wrote:

> 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 at gmail.com>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 <sakesun at gmail.com>
>> 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 ?
>> > _______________________________________________
>> > pypy-dev at codespeak.net
>> > http://codespeak.net/mailman/listinfo/pypy-dev
>> >
>>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/pypy-dev/attachments/20100819/dd415df9/attachment.html>


More information about the Pypy-dev mailing list