python interpreter conflicts with gettext's _()

Hello

I've been busy internationalizing my wxpython app using the gettext module. My
app has a shell (I use orbtech's shell class from wx.py). Within this shell,
I'd like to access some of the variables I use inside the main app.
Therefore, I did something like
mywantedlocals=dict()
mywantedlocals["myvar"]=myvar
myshell=Shell(.....,locals=mywantedlocals,...)

However, my app's menus stop responding as soon as I type something in the
shell, because the global "_" symbol gets overridden by the one from the
shell, which returns the result of the last command executed . Since "_" can
be equal to anything (it can even be a number), python gives me many errors,
and any i18n'd code stops working. For example, if I type
5 <enter>
in the shell, "_" becomes 5 instead of the gettext function in my main program
as well...

Does anyone know how to solve this?

Regards,
  David

···

--
You'd better smile when they watch you, smile like you're in control.
    -- Smile, "Was (Not Was)"

David Sibai wrote:

Hello

I've been busy internationalizing my wxpython app using the gettext module. My app has a shell (I use orbtech's shell class from wx.py). Within this shell, I'd like to access some of the variables I use inside the main app. Therefore, I did something like
mywantedlocals=dict()
mywantedlocals["myvar"]=myvar
myshell=Shell(.....,locals=mywantedlocals,...)

However, my app's menus stop responding as soon as I type something in the shell, because the global "_" symbol gets overridden by the one from the shell, which returns the result of the last command executed . Since "_" can be equal to anything (it can even be a number), python gives me many errors, and any i18n'd code stops working. For example, if I type 5 <enter>
in the shell, "_" becomes 5 instead of the gettext function in my main program as well...

Does anyone know how to solve this?

The sys.displayhook function is the culprit here, but you can replace it with your own function that does not reset the __builtins__._:

  def _displayHook(obj):
    sys.stdout.write(str(obj))

  sys.displayhook = _displayHook

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!