4 ms·
I miss print as a statement. Especially when I try to debug fast in dummy scripts, and when debugging in REPL (bpython, ipython). I always forget it's a functio
by t0mk 11y ago
I miss print as a statement. Especially when I try to debug fast in dummy scripts, and when debugging in REPL (bpython, ipython). I always forget it's a function, and then I have to move the cursor before the printed symbol, type the left parenthesis, move after the symbol, then the right one. It's kind of annoying.
- kragniz 11y agoI also miss it. Those parens are a bit annoying to type when doing print debugging. I really appreciate the fact that it makes a lot more sense for it to be a function, however. In time, I'm sure we'll all get used to it.
- masklinn 11y ago> I miss print as a statement. I don't. It's a habit change so sure once in a while I still forget the parens, but the function form is way more readable when doing anything beyond a bare print[0] — not to mention it can plain do more useful stuff — and I can now put a print function in a lambda instead of needing bullshit like sys.stdout.write(' '.join(map(str, [a, bunch, of, vars]))) [0] no magical easy to miss terminal comma or sigil soup for non-stdout printing, clear and readable keyword parameters instead
- t0mk 11y agoYou mention print in lambda, and it's also in the article. I don't think that's good enough reason for killing the usability of print statement in repl. I'd consider it quite a weird piece of code if I'd see print in lambda, or passed to something from functools. If "sys.stdout.write" would be there instead of the "print", I'd see it equally weird. Both is (probably unnecessary) giving away the simplicity of Python. I debug in REPL quite a lot and I don't do functional magic with print at all (at the moment). That's dragging me away from Python 3. Other people might have it different.
- wickawic 11y agoIt seems silly that typing a single extra character at the end of the line (noting that the left parenthesis was previously a space) is "dragging you away from python". It is also worth noting that the IPython repl will close parentheses for you, so you actually don't have to type any more characters at all!
- ubertaco 11y ago>I don't think that's good enough reason for killing the usability of print statement in repl. I really don't think the difference between print(some_var) and print some_var constitutes "killing usability". > I'd consider it quite a weird piece of code if I'd see print in lambda Granted, I don't do much Python these days (I have become enamored with more strongly-typed langs lately), but my impression is that lambdas are uncommon in python, instead preferring relatively-inexpensive toplevel function defs instead. > I debug in REPL quite a lot and I don't do functional magic with print at all (at the moment) Consider a case where I'm debugging why my function foo(x) is failing for at least one of [42, 333, -57, 0, None, 33], but I don't know which one. It's not unheard of to do some step-by-step binary-search stuff like this: >> [print(foo(x)) for x in test_cases[0:3]] # repl doesn't blow up >> [print(foo(x)) for x in test_cases[3:]] # repl blows up as expected >> [print(foo(x)) for x in test_cases[4:]] # repl doesn't blow up, so now I know that foo(0) has a bug Now, you might look at this and point out that I don't actually need to print(foo(x)) at all, that the REPL will display the resulting arrays anyways. And you're right! So even here, the difference between "print(x)" and "print x" doesn't "kill usability", since it's a moot point either way. I think in day-to-day use, even at a REPL, it's a "six of one, half-dozen of another" scenario with no major wins either way. In teaching Python, it's a win because it's more consistent -- you don't have to teach people "this is how it looks to call a function -- except print, it's not really a real function, it's special, so make sure you remember this one exception." And in building Python, it means one fewer special case to maintain for the interpreter and language.
- danso 11y agoHaving print() as a function was something that helped convince me to teach Python 3, as opposed to 2.x. Don't get me wrong, in Ruby, I'm completely lax in using parentheses in function calls. But when explaining syntax to newbies, about how regular it is, and how it's easy to determine what's a function and what's not by use of parentheses...I want as few as exceptions as possible...and print() is something that beginners especially use a lot.