Disabling the magic "last expression" _ variable

Peter Otten __peter__ at web.de
Tue Jul 1 07:22:37 EDT 2008


Koen Vossen wrote:

> A project I'm currently working on uses Turbogears as a framework. I'd
> like to interact with it using the tg-admin shell. We also use gettext's
> _() function for internationalization. Now, this function is overwritten
> in interactive mode, which causes annoying exceptions. Is it possible to
> disable this behavior?

[correct overzealous snip]

>>> import sys
>>> def displayhook(result):
...     if result is not None:
...             __builtins__._last = result
...             print result
...
>>> sys.displayhook = displayhook
>>> _
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name '_' is not defined
>>> "yadda"
yadda
>>> _
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name '_' is not defined
>>> _last
yadda


Peter



More information about the Python-list mailing list