[Python-3000] print() parameters in py3k

Guido van Rossum guido at python.org
Tue Nov 21 02:35:41 CET 2006


On 11/20/06, Jim Jewett <jimjjewett at gmail.com> wrote:
> On 11/20/06, Barry Warsaw <barry at python.org> wrote:
> > -----BEGIN PGP SIGNED MESSAGE-----
> > Hash: SHA1
> >
> > On Nov 20, 2006, at 12:14 PM, Josiah Carlson wrote:
> >
> > > How much print statement rewriting do you want to do?  Me, I'd like to
> > > get away with as little as possible.  Adding parenthesis isn't that
> > > bad.
> > > Changing everything to use a printf-style would be 1) annoying, 2)
> > > unnecessary, and 3) I hate printf.
>
> > Are we going to include a flawless transformation script for Python
> > 3k?  If not, then I'm pretty much resigned to rewriting them by hand
> > anyway.
>
> Assuming no further changes to PEP 3105, then it should be possible,
> at least for the print statement.
>
> Just parse the thing into statements; when you get to a print
> statement make the string replacement before writing it back out.
>
>   The "print" literal translates into "print(" ... ")"
>
>   ">>" file_expression moves to the end and translates into
> "file="file_expression
>
>   the printable_expression stays the same
>
>   a trailing comma translates into "end=''" (an empty string)

No, end=" " (i.e. a single space). And the translation can't be
perfect, due to the dropping of softspace. But IMO for code using
print statements few people will mind occasionally seeing a line
ending with a space before the newline.

>   (legacy code never uses the sep keyword)

-- 
--Guido van Rossum (home page: http://www.python.org/~guido/)


More information about the Python-3000 mailing list