|
From: Koen Vossen on 1 Jul 2008 07:10 A project I'm currently working on uses Turbogears as a framework. I'd like to interact with it using the tg-admin shell. We also use gettext's _() function for internationalization. Now, this function is overwritten in interactive mode, which causes annoying exceptions. Is it possible to disable this behavior?
From: Peter Otten on 1 Jul 2008 07:20 Koen Vossen wrote: > A project I'm currently working on uses Turbogears as a framework. I'd > like to interact with it using the tg-admin shell. We also use gettext's > _() function for internationalization. Now, this function is overwritten > in interactive mode, which causes annoying exceptions. Is it possible to > disable this behavior? >>> import sys >>> def displayhook(result): .... if result is not None: .... __builtins__._last = result .... print result .... >>> "yadda" yadda >>> _ Traceback (most recent call last): File "<stdin>", line 1, in <module> NameError: name '_' is not defined >>> _last yadda Peter
From: Peter Otten on 1 Jul 2008 07:22 Koen Vossen wrote: > A project I'm currently working on uses Turbogears as a framework. I'd > like to interact with it using the tg-admin shell. We also use gettext's > _() function for internationalization. Now, this function is overwritten > in interactive mode, which causes annoying exceptions. Is it possible to > disable this behavior? [correct overzealous snip] >>> import sys >>> def displayhook(result): .... if result is not None: .... __builtins__._last = result .... print result .... >>> sys.displayhook = displayhook >>> _ Traceback (most recent call last): File "<stdin>", line 1, in <module> NameError: name '_' is not defined >>> "yadda" yadda >>> _ Traceback (most recent call last): File "<stdin>", line 1, in <module> NameError: name '_' is not defined >>> _last yadda Peter
From: Ben Finney on 1 Jul 2008 10:30 Peter Otten <__peter__(a)web.de> writes: > >>> import sys > >>> def displayhook(result): > ... if result is not None: > ... __builtins__._last = result > ... print result > ... Better is to explicitly import the name '__builtin__' <URL:http://www.python.org/doc/lib/module-builtin>. The name '__builtins__' is an implementation detail not guaranteed to be present in any particular implementation. import __builtin__ import sys def displayhook(result): if result is not None: __builtin__._last = result print result -- \ “If you continue running Windows, your system may become | `\ unstable.” —Microsoft, Windows 95 error message | _o__) | Ben Finney
|
Pages: 1 Prev: problem with exec and locals() Next: Scope and program structure problems |