How to use _ in interactive mode

P

pythonic

Hi,

I use '_' for localization in my program. The problem is when testing
the program using python intractive mode I lose _ function.
One solution is put following in PYTHONSTARTUP file.
--
import readline
def __enforce_underscore__ (): __builtins__._ = str
readline.set_pre_input_hook (__enforce_underscore__)
--

My program in startup imports a module which customize the env.
Putting above in that module doesn't solve the problem. Any
cleaner/better way?
Honestly, I was expecting once overriden _ in builtins it would be honored.

This how I reproduce the problem.

Python 2.3.3 (#1, May 7 2004, 10:31:40)
def localizer(s): return str(s)
__builtins__.__dict__['_'] = localizer
_
_('some text') 'some text'
_ 'some text'
_('some text')
Traceback (most recent call last):
File "<stdin>", line 1, in ?
TypeError: 'str' object is not callable

TIA.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top