Re:Extend Python 2.7 life till 2020
by jimmaswell on Sunday April 13, 2014 @03:51PM
(#7582686)
can't use print x anymore, which also gets rid of "print x,", which printed something without making a newline, for one thing.
[ Parent
| on HN ]
Re:Extend Python 2.7 life till 2020
by dragonwriter on Sunday April 13, 2014 @04:15PM
(#7582798)
> can't use print x anymore
Yes, its a function not a statement, so its now print(x).
> which also gets rid of "print x,", which printed something without making a newline, for one thing.
Sure, you have to do: print(x,end=' ')
if you want to space separate things printed on separate code lines on the same output line.
Of course, if the extra keystrokes bother you, its really not much one-time cost to toss together a library that provides a function that gets rid of them, while keeping the rest of the power of the print function:
def p(*args, **kwargs):
kwargs = {'end': ' '}.update(kwargs)
print(*args,**kwargs)
Though if I was going to bother to do that, I'd probably do it with the same separator for multiple items on the same line as for items on different lines: def p(*args, **kwargs):
kwargs = {'sep': ' ', 'end': ' '}.update(kwargs)
print(*args,**kwargs)
or, further leveraging print-is-a-function: import functools
p = functools.partial(print, sep=' ',end=' ')
Re:Extend Python 2.7 life till 2020
by SoftwareMaven on Sunday April 13, 2014 @04:00PM
(#7582721)
print(x, end='')
Not quite as nice, but not exactly unusable.
Re:Extend Python 2.7 life till 2020
by jimmaswell on Sunday April 13, 2014 @09:57PM
(#7584108)
It's a lot less "pythonic".
Dunno. The 3 way is more "Explicit is better than implicit." Though it's a shame Python 3 messes up http://xkcd.com/353/