Problem with mixing doctest with gettext _()

Skip Montanaro skip at pobox.com
Fri Feb 27 11:47:58 EST 2004


    Pierre> I tried that, but it only works for the first call...

:-)

    Pierre> [Shell buffer started: python.exe]
    Pierre> Python 2.3.3 (#51, Dec 18 2003, 20:22:39) [MSC v.1200 32 bit (Intel)] on 
    Pierre> win32
    Pierre> Type "help", "copyright", "credits" or "license" for more information.
    >>>> import __builtin__
    >>>> def foo(s): return s
    Pierre> ...
    >>>> __builtin__._ = foo
    >>>> _
    Pierre> <function foo at 0x008F98B0>
    >>>> _
    Pierre> <function foo at 0x008F98B0>
    >>>> _('hi')
    Pierre> 'hi'
    >>>> _
    Pierre> 'hi'
    >>>> _('Hello')
    Pierre> Traceback (most recent call last):
    Pierre>    File "<stdin>", line 1, in ?
    Pierre> TypeError: 'str' object is not callable
    >>>> 

That's true.  In interactive mode _ is assigned the value of the last
expression evaluated.  Try it from a script.

Skip




More information about the Python-list mailing list