Problem with mixing doctest with gettext _()
Pierre Rouleau
prouleau at impathnetworks.com
Fri Feb 27 12:39:00 EST 2004
Peter Otten wrote:
> Pierre Rouleau wrote:
>
>
>>Skip Montanaro wrote:
>>
>>
>>>If you really want a dummy _() you can also stuff your version into
>>>builtins:
>>>
>>> >>> import __builtin__
>>> >>> def foo(s): return s
>>> ...
>>> >>> __builtin__._ = foo
>>> >>> _
>>> <function foo at 0x1d6670>
>>> >>> _("hi")
>>> 'hi'
>>
>>I tried that, but it only works for the first call...
>
>
> Setting __builtin__._ to the result of the last calculation is a side effect
> of sys.displayhook. Therefore you need to change that too:
>
> Python 2.3.3 (#1, Jan 3 2004, 13:57:08)
> [GCC 3.2] on linux2
> Type "help", "copyright", "credits" or "license" for more information.
>
>>>>import sys
>>>>def mydisplayhook(a):
>
> ... if a is not None: sys.stdout.write("%r\n" % a)
> ...
>
>>>>def foo(s): return s
>
> ...
>
>>>>sys.displayhook = mydisplayhook
>>>>import __builtin__
>>>>__builtin__._ = foo
>>>>_("hi")
>
> 'hi'
>
>>>>_("hello")
>
> 'hello'
>
Thanks Peter, it does work!
More information about the Python-list
mailing list