Here's the reason I hate the print statement in 2.x.
>>> something()
>>> print something()
worthless object has no useful __str__
, Fine, I can deal, look at it some more.
>>> dir(something())
['foo', 'bar', 'baz', 'wonderful']
>>> help(something().foo)
"foo(self, callable)"
hmm.. so does that callable take arguments?
>>> something().foo(print)
something().foo(print)
^
SyntaxError: invalid syntax
>>> something().foo(lambda *args: print(*args))
something().foo(lambda *args: print(*args))
^
SyntaxError: invalid syntax
So... I have to either define a function to use
>>> def myPrint(*args): print *args
def myPrint(*args): print *args
^
SyntaxError: invalid syntax
>>> def myPrint(*args): print args
...
>>> myPrint(1)
(1,)
Shudder, or use sys.stdout.write
, which is almost as cludgy, since it has very different behavior from print
. It also looks different, which means I'll almost never remember that it exists.
Using print
statements in a short, one-off type facility and then improving it to use logging or something better is just inelegant. If print worked like those things, and especially could be used with high order functions, then it would be better than just the thing you use when you don't use real logging or real debuggers.