Disabling the magic "last expression" _ variable

Ben Finney bignose+hates-spam at benfinney.id.au
Tue Jul 1 10:30:45 EDT 2008


Peter Otten <__peter__ at web.de> writes:

> >>> import sys
> >>> def displayhook(result):
> ...     if result is not None:
> ...             __builtins__._last = result
> ...             print result
> ...

Better is to explicitly import the name '__builtin__'
<URL:http://www.python.org/doc/lib/module-builtin>. The name
'__builtins__' is an implementation detail not guaranteed to be
present in any particular implementation.

    import __builtin__
    import sys
    def displayhook(result):
        if result is not None:
            __builtin__._last = result
            print result

-- 
 \            “If you continue running Windows, your system may become |
  `\                   unstable.” —Microsoft, Windows 95 error message |
_o__)                                                                  |
Ben Finney



More information about the Python-list mailing list