Why has python3 been created as a seperate language where there is still python2.7 ?
Steven D'Aprano
steve+comp.lang.python at pearwood.info
Tue Jun 26 03:40:40 EDT 2012
On Tue, 26 Jun 2012 02:15:17 -0400, Devin Jeanpierre wrote:
>> Making print a statement in the first place was a mistake, but
>> fortunately it was a simple enough mistake to rectify once the need for
>> backward compatibility was relaxed.
>
> Hmmm, why is the function so much better than the statement? You like
> using it in expressions? Or is it that you like passing it in as a
> callback?
Simplicity: there doesn't seem to be anything special about print that
requires it to be syntax instead of just a built-in function. Nearly
everything else which is handled by syntax is special: assignment,
deletion, imports, flow control. (Decorators are the obvious exception,
but they are pure syntactic sugar.)
Consistency: print as a function isn't a special case to be learned.
There's no need to memorise magic syntax to control it, you just pass
ordinary arguments using ordinary syntax. Instead of arcane and bizarre
special cases like this:
print >>sys.stderr, spam, ham, eggs,
you just use:
print(spam, ham, eggs, file=sys.stderr, end='')
While it's a tad longer, there's no special syntax to be learned.
Practicality: as a function, you can use print anywhere you can use other
functions. You can bind it to another name, pass it as argument to
another function such as help(), store it in a list, use it as a
callback, or monkey-patch it, without needing to write a wrapper
"print_" (or "prnt", "pr", etc.) around it.
Compare that to print as a statement, which only has one argument in
favour: backwards compatibility.
--
Steven
More information about the Python-list
mailing list