473,800 Members | 2,586 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Disabling the magic "last expression" _ variable

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 internationaliz ation. Now, this function is overwritten
in interactive mode, which causes annoying exceptions. Is it possible to
disable this behavior?
Jul 1 '08 #1
3 1389
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 internationaliz ation. Now, this function is overwritten
in interactive mode, which causes annoying exceptions. Is it possible to
disable this behavior?
>>import sys
def displayhook(res ult):
.... if result is not None:
.... __builtins__._l ast = result
.... print result
....
>>"yadda"
yadda
>>_
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name '_' is not defined
>>_last
yadda

Peter
Jul 1 '08 #2
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 internationaliz ation. 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(res ult):
.... if result is not None:
.... __builtins__._l ast = result
.... print result
....
>>sys.displayho ok = 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
Jul 1 '08 #3
Peter Otten <__*******@web. dewrites:
>import sys
def displayhook(res ult):
... if result is not None:
... __builtins__._l ast = 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(res ult):
if result is not None:
__builtin__._la st = result
print result

--
\ “If you continue running Windows, your system may become |
`\ unstable.” —Microsoft, Windows 95 error message |
_o__) |
Ben Finney
Jul 1 '08 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
2072
by: sbd! | last post by:
I had a problem with string which have some \ chars at the end of the string. For example: $String = "I want this **** out of here\\\\\\\\\"; I needed to remove it useing regular expression...i thinked that something like "/\\+$/" is enough but i was wrong. I made some tries and finaly i removed "\" chars it with "/\\\+$/". It works (i'm proud with myself :)), but i can't understand why \\\ matchs single \, and \\ not...
4
1689
by: Roy Yao | last post by:
Does it mean "(sizeof(int))* (p)" or "sizeof( (int)(*p) )" ? According to my analysis, operator sizeof, (type) and * have the same precedence, and they combine from right to left. Then this expression should equal to "sizeof( (int)(*p) )", but the compiler does NOT think so. Why? Can anyone help me? Thanks. Best regards. Roy
7
2155
by: Scott W Gifford | last post by:
Hello, I'm considering using XML to represent a stream of location information, and XPath to do queries against it. I've got most of it figured out (at least on paper), but I can't figure out how to create an XPath statement asking for the "last node with a value less than" a given value. I need this to be able to ask "Where was Scott at 11:00 yesterday", which should find the last sighting of Scott before or at 11:00
32
4158
by: James Curran | last post by:
I'd like to make the following proposal for a new feature for the C# language. I have no connection with the C# team at Microsoft. I'm posting it here to gather input to refine it, in an "open Source" manner, and in an attempt to build a ground-swell of support to convince the folks at Microsoft to add it. Proposal: "first:" "last:" sections in a "foreach" block The problem: The foreach statement allows iterating over all the...
13
27443
by: hn.ft.pris | last post by:
Hi: I have the following simple program: #include<iostream> using namespace std; int main(int argc, char* argv){ const double L = 1.234; const int T = static_cast<const int>(L); int arr;
4
2747
by: =?Utf-8?B?SmFu?= | last post by:
In my application the user can configure automation-scripts by inserting different "actions" into a "procedure". These different procedure- and action-objects are all translated into C# code before execution. One "action" type is an expression-evaluator. At the moment the expression the user writes into the action is just inserted into the generated C# code unchanged. The problem is the variables in my system and in the "procedures";...
4
3085
by: jaime | last post by:
Hi again all. Given the line: const int x=5; Can I then use "x" as a constant expression? (By "constant expression", I mean "constant expression" as defined in the C99 standard) I've been searching google for 2 days now trying to answer this myself, and I'm just getting more and more confused (some things I read make me think "yes", while some things I read make me think "no").
56
6781
by: Adem | last post by:
C/C++ language proposal: Change the 'case expression' from "integral constant-expression" to "integral expression" The C++ Standard (ISO/IEC 14882, Second edition, 2003-10-15) says under 6.4.2(2) : case constant-expression : I propose that the case expression of the switch statement be changed from "integral constant-expression" to "integral expression".
0
9551
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10507
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10279
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10036
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9092
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development projectplanning, coding, testing, and deploymentwithout human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6815
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5607
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4150
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2948
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.