3 ms·
I do. There's a huge advantage that print as a construct has: print >>fp, ... Yes, you can do the same thing with a kwarg on the print function, but it goes at
by daeken 6y ago
I do. There's a huge advantage that print as a construct has: print >>fp, ...
Yes, you can do the same thing with a kwarg on the print function, but it goes at the end of the line and ends up substantially messier in practice. This is the #1 reason that I still write Python 2 every single day; it makes a huge difference for code generation tasks.
- ptx 6y agoGood point about the old syntax putting the file at the start rather than the end, but if you have a lot of code like that you could just do this: p = partial(print, file=fp) p("foo") p("bar")
- daeken 6y agoUnfortunately, that only solves the case of printing strings with newlines, not the case where I might want to continue the line with a space instead, where I'd normally just add "," at the end and call it good. There are absolutely ways around their poor decision, but at the end of the day, the print function instead of statement is a bad fit for some use cases.