Re: Last expression vrbl (was: python strings ( function func_doc strings ))
Wed, 27 Apr 1994 14:19:46 +0200

> > ... The best idea would be to also introduce a magic global variable
> > that receives the result of the last expression printed this way [as a
> > top-level interactive expression] -- useful for a desk calculator-like
> > use of interactive Python.

> Ya! Go for it. I suggest "z" as the magic global variable: if it ain't
> short to type, it ain't helpful; believe "z" is rarely used interactively
> (whereas a, b, c, i, j, k, n, x, y are); and "last letter of the alphabet"
> is so very suggestive of "last expression" <snort>.

Well, since (by definition) there will be no scripts that rely on this
feature (since it will work ONLY interactively) we can experiment with
different names. I found a minimal set of change to compile.c (7
lines) that generates POP_TOP instructions instead of PRINT_EXPR
instructions everywhere except for interactively entered commands, and
a one-line change to ceval.c to assign the printed value to the local
variable "_". (I don't like arbitrary "cute" solutions like "it", nor
one-letter variables like "z" -- I'm sure somewhere there's a user
doing a kind of math where the most common variable is called "z"...)

Later we could invent more flexible schemes -- the most flexible being
a user-defined function assigned to a variable in module sys that is
called to print the value...


--Guido van Rossum, CWI, Amsterdam <>
URL: <>