gettext and the interpreter

Discussion in 'Python' started by Hans-Joachim Widmaier, Apr 3, 2004.

  1. 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?

    Hans-Joachim
    Hans-Joachim Widmaier, Apr 3, 2004
    #1
    1. Advertising

  2. Hans-Joachim Widmaier

    Peter Otten Guest

    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
    Peter Otten, Apr 3, 2004
    #2
    1. Advertising

  3. Am Sat, 03 Apr 2004 23:22:47 +0200 schrieb Peter Otten:

    > Try redefining sys.displayhook, e. g.:


    Thanks a lot! This is the stuff I keep having problems with finding in the
    docs.

    [Sorry for answering late, but Google gave me only empty pages, and I'm
    just now able to do it properly.]

    Hans-Joachim
    Hans-Joachim Widmaier, Apr 8, 2004
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Daniel Leidert
    Replies:
    0
    Views:
    658
    Daniel Leidert
    May 28, 2005
  2. Daniele
    Replies:
    2
    Views:
    378
    Daniele
    Oct 14, 2004
  3. Terry Hancock

    gettext and "disambiguating comments"

    Terry Hancock, Jul 11, 2005, in forum: Python
    Replies:
    1
    Views:
    487
    =?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=
    Jul 11, 2005
  4. =?iso-8859-1?B?QW5kcuk=?=
    Replies:
    0
    Views:
    416
    =?iso-8859-1?B?QW5kcuk=?=
    Mar 2, 2006
  5. Replies:
    3
    Views:
    746
    Ziga Seilnacht
    Jan 3, 2007
Loading...

Share This Page