gettext and the interpreter

Peter Otten __peter__ at web.de
Sat Apr 3 16:22:47 EST 2004


Hans-Joachim Widmaier wrote:

> Recently I wanted to do some debugging using one module of my first
> Python program using the gettext module. I just didn't find a way to
> disable the interpreter binding the last result to _, which ought to
> be (and stay) a function.
> 
> Anybody got an idea how to do it?

Try redefining sys.displayhook, e. g.:

>>> import sys, __builtin__
>>> def myhook(value):
...     if value is not None:
...             __builtin__.__last__ = value
...             sys.stdout.write("%r\n" % value)
...
>>> sys.displayhook = myhook

Now the last non-None value will be stored in __last__ instead of _:

>>> 1
1
>>> _
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
NameError: name '_' is not defined
>>> __last__
1

Peter




More information about the Python-list mailing list