gratuitous new features in 2.0
Manuel Gutierrez Algaba
thor at localhost.localdomain
Sat Aug 26 16:16:29 EDT 2000
On Sat, Guido van Rossum <guido at beopen.com> wrote:
>"John W. Baxter" <jwbnews at scandaroon.com> writes:
>> Guido is so darn sharp that it's easy to agree which his
>> positions...particularly after he's had a give and take with other darn
>> sharp folks and taken their good ideas into account.
>
>Thanks! ;-) Please take the following idea into account:
>
>Suppose you have written a function that uses the print statement:
>
> def table(n):
> for j in range(1, n+1):
> for i in range(1, n+1):
> print i, 'x', j, '=', i*j
> print
>
>Now you are asked to make it print to another file -- a standard
>example of how software typically is asked to evolve.
What about ?:
def table(n, file=None):
for j in range(1, n+1):
for i in range(1, n+1):
if file:
file.write(`i` " x " `j` " = " `i*j`)
else:
print i, 'x', j, '=', i*j
if file:
file.write("\n")
else:
print
And, without knowing it, you've given a definitive _good_
reason to keeping prints:
"""
The syntax i, 'x', j, '=', i*j
is __much__ clearer and simpler than __any other else__
especially than ("%d * %d = %d\n" % (i, j, i*j))
"""
Perhaps we could have a generate a new syntax por a
"i, 'x', j, '=', i*j"-expression.
Having print/write as a function would fine too, but
print is not only the print but the "comma-separated" expresion!
Hoping-to-being-as-sharp-as-guido-'ly yours
---
MGA
More information about the Python-list
mailing list