Pep 3105: the end of print?

Fuzzyman fuzzyman at gmail.com
Fri Feb 16 09:42:55 EST 2007


On Feb 16, 2:01 pm, "Edward K Ream" <edream... at charter.net> wrote:
> > Why won't it be possible to make 'print' in Python 3 that supports all
> > the functionality of the current print statement, and then translate to
> > that ?
> > I saw an assertion to the effect that it wasn't possible - but no proof.
>
> As discussed in the original post, the problem is the reverse:  the Python
> 2.x print statement does not support the keyword args required by the pep,
> so that print(foo) **in Python 2.x** can not simulate the effect of the
> print statement with a trailing comma.  Here is the theorum carefully stated
> and proved.
>
> Theorem:  is not possible to define a function called print in Python 3.x
> such that
>
> A) print (whatever) is syntaxtically valid in Python 2.x and
>
> B) print(whatever) outputs what 'print whatever' outputs  in Python 2.x for
> all values of 'whatever'.
>
> Proof:
>
> It is impossible for the print function to simulate the effect of the print
> statement with a trailing comma.  Indeed, print ('line'), and print
> ('line',) (note the position of the commas) are valid in Python 2.x, but
> neither does what is wanted.  And print('line',end='') is invalid in Python
> 2.x.  Let's look at some examples:
>
> 1. The following works (prints 'line after\n') in Python 2.x, but will not
> suppress the newline in Python 3.x:
>
> print('line'),
> print('after')
>
> 2. The following doesn't work in Python 2.x.  (It prints
> "('line',)\nafter").
>
> print ('line',)
> print ('after')
>
> 3.  print ('line',end='') produces a syntax error in Python 2.x:
>
>     print ('line',end='')
>                      ^
> SyntaxError: invalid syntax
>
> That's the proof.  Can you find a flaw in it?
>

I mentioned the 2to3 translator- the goal of which is *precisely* to
allow you to write code that will run on Python 2.X and when
translated run under Python 3.0.

You then repeated the problem with the 'print' statement.

It may be true that you won't be able to write code that runs
untranslated on 2 and 3. That doesn't stop you writing code for Python
2.X, then translating a version for Python 3. (Uhm... indeed that's
the point of 2to3.)

So you only have one codebase to maintain and you can still use
print...

Fuzzyman
http://www.voidspace.org.uk/python/articles.shtml



> Edward
> --------------------------------------------------------------------
> Edward K. Ream   email:  edream... at charter.net
> Leo:http://webpages.charter.net/edreamleo/front.html
> --------------------------------------------------------------------





More information about the Python-list mailing list