displayhook = pprint & _ not happy together
Sandy Norton
sandskyfly at hotmail.com
Sun Aug 26 09:40:33 EDT 2001
>From the documentation:
"In interactive mode, the last printed expression is assigned to the
variable _. This means that when you are using Python as a desk
calculator, it is somewhat easier to continue calculations, for
example:
>>> tax = 12.5 / 100
>>> price = 100.50
>>> price * tax
12.5625
>>> price + _
113.0625
>>> round(_, 2)
113.06
>>>
"
In the startup.py file identified in the PYTHONSTARTUP environment
variable, I've got:
import sys, pprint
sys.displayhook = pprint.pprint
del pprint, sys
which works fine in regular cases and gives me pretty-printed
interactive output (which I dearly like). But I've just noticed that
doing this makes the _ non-functional. For example:
Python 2.1.1 (#22, Aug 22 2001, 01:24:03) [MSC 32 bit (Intel)] on
win32
Type "help", "copyright", "credits" or "license" for more information.
>>> 1 + 2
3
>>> _ + 3
Traceback (most recent call last):
File "<stdin>", line 1, in ?
NameError: name '_' is not defined
>>>
Bug or feature?
regards,
Sandy
More information about the Python-list
mailing list