Replacement for print in Python 3.0
Guido van Rossum suggested:
stream.write(a1, a2, ...) stream.writeln(a1, a2, ...) stream.writef(fmt, a1, a2, ...)
builtin functions write(), writeln(), writef() that call the corresponding method on sys.stdout.
These seem good, except that write typically matches read, and I'm not sure how well the equivalents would work. (They can be defined; they just feel a little too fragile, like C's input.)
Another real problem with print is that, while the automatic insertion of spaces is nice for beginners, it often gets in the way, and what you have to do to avoid this is pretty nasty: either drop print altogether in favor of sys.stdout.write(), or use string concatenation or a format string, assuming you have all the pieces available at the same time (which often you don't).
I usually take "I need to get rid of spaces" as an indication that I care about exact (not just readable, but exact) formatting, and *should* use either write or a format string (possibly waiting to collect the data). Putting the spaces back in (without a format string) would be even worse. Charles Cazabon's pointed out that it *could* be as simple as writeln(' '.join( ... )) but if there isn't a builtin alias, people (at least those not intimidated by the magic required to get simple output) *will* do things at least as bad as writeln(a, " ", b, " ", c) or as bugprone as # oops, format string and debug vars got out of sync writef(" Current Vals:%s %d %d%s", curval, i, k, name, age) -jJ
Jim Jewett wrote:
Another real problem with print is that, while the automatic insertion of spaces is nice for beginners, it often gets in the way, and what you have to do to avoid this is pretty nasty: either drop print altogether in favor of sys.stdout.write(), or use string concatenation or a format string, assuming you have all the pieces available at the same time (which often you don't).
I usually take "I need to get rid of spaces" as an indication that I care about exact (not just readable, but exact) formatting, and *should* use either write or a format string (possibly waiting to collect the data).
Putting the spaces back in (without a format string) would be even worse. Charles Cazabon's pointed out that it *could* be as simple as
writeln(' '.join( ... ))
Why not just offer an addition method ? examine(x,y,z) # print with spaces Or some other suitable name. Cheers, Ron
On 9/2/05, Ron Adam
Jim Jewett wrote:
Putting the spaces back in (without a format string) would be even worse. Charles Cazabon's pointed out that it *could* be as simple as
writeln(' '.join( ... ))
Why not just offer an addition method ?
examine(x,y,z) # print with spaces
Because we're now up to *four* stream methods, plus the same number of builtins, to do what one statement currently does? (BTW, the ' '.join() idiom has a minor disadvantage in that it *builds* the output string, whereas print doesn't. Not a major issue, given the typical sizes of strings to be output, but it's another cost nevertheless...) Paul.
Paul Moore wrote:
On 9/2/05, Ron Adam
wrote: Jim Jewett wrote:
Putting the spaces back in (without a format string) would be even worse. Charles Cazabon's pointed out that it *could* be as simple as
writeln(' '.join( ... ))
Why not just offer an addition method ?
examine(x,y,z) # print with spaces
Because we're now up to *four* stream methods, plus the same number of builtins, to do what one statement currently does?
I'm not sure having one statement that can do several things with multiple syntax's is better than having multiple methods each with a single syntax. How is this different than having two methods in the case of partition() and rpartiion(). Ron
participants (3)
-
Jim Jewett
-
Paul Moore
-
Ron Adam