when should I explicitly close a file?

Alf P. Steinbach alfps at start.no
Sat Apr 24 09:30:26 CEST 2010

* Steven D'Aprano:
> On Fri, 23 Apr 2010 13:19:41 +0200, Alf P. Steinbach wrote:
>> But for a literal context-free interpretation e.g. the 'sys.getrefcount'
>> function is not documented as CPython only and thus an implementation
>> that didn't do reference counting would not be a conforming Python
>> implementation.
> Since Jython and IronPython are conforming Python implementations, and 
> Guido has started making policy decisions specifically to support these 
> other implementations (e.g. the language feature moratorium, PEP 3003), I 
> think we can assume that this is a documentation bug.

The documentation for Jython specifies the same for 'sys.getrefcount'.

However, testing:

*sys-package-mgr*: processing new jar, 'C:\Program Files\jython2.5.1\jython.jar'
*sys-package-mgr*: processing new jar, 'C:\Program 
*sys-package-mgr*: processing new jar, 'C:\Program Files\Java\jre6\lib\rt.jar'
*sys-package-mgr*: processing new jar, 'C:\Program Files\Java\jre6\lib\jsse.jar'
*sys-package-mgr*: processing new jar, 'C:\Program Files\Java\jre6\lib\jce.jar'
*sys-package-mgr*: processing new jar, 'C:\Program Files\Java\jre6\lib\charsets.jar'
*sys-package-mgr*: processing new jar, 'C:\Program 
*sys-package-mgr*: processing new jar, 'C:\Program 
*sys-package-mgr*: processing new jar, 'C:\Program 
*sys-package-mgr*: processing new jar, 'C:\Program 
*sys-package-mgr*: processing new jar, 'C:\Program 
A created
Traceback (most recent call last):
   File "c:\test\refcount.py", line 17, in <module>
     writeln( str( sys.getrefcount( a ) - 1 ) )
AttributeError: 'systemstate' object has no attribute 'getrefcount'

> However, a Python implementation that always returned 0 for 
> sys.getrefcount would technically satisfy the word of the documentation, 
> if not the spirit.


OK, learned something new: I though Jython actually implemented getrefcount.

The Jython docs says it does...


- Alf

More information about the Python-list mailing list