eryksun added the comment:

In interactive mode the extra reference is held by the "_" built-in variable. 

    >>> a
    'test string A'
    >>> del __builtin__._; sys.getrefcount(a) - 1
    1

Look at the following disassembled code, compiled in the 'single' interactive 
mode:

    >>> dis.dis(compile('a', '', 'single'))
      1           0 LOAD_NAME                0 (a)
                  3 PRINT_EXPR          
                  4 LOAD_CONST               0 (None)
                  7 RETURN_VALUE  

[PRINT_EXPR][1] calls [sys.displayhook][2]. The default display hook prints a 
non-None value and sets it as __builtin__._. You can replace this with your own 
display hook. The original function is always available as sys.__displayhook__.

[1]: https://hg.python.org/cpython/file/v2.7.10/Python/ceval.c#l1727
[2]: https://docs.python.org/2/library/sys.html#sys.displayhook

----------
nosy: +eryksun
resolution:  -> not a bug
stage:  -> resolved
status: open -> closed

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue25273>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to