Python 3

Robert Collins robertc at robertcollins.net
Wed Jun 23 06:55:52 BST 2010


On Wed, Jun 23, 2010 at 5:52 PM, Russel Winder <russel at russel.org.uk> wrote:
> Robert,
>
> On Wed, 2010-06-23 at 09:47 +1200, Robert Collins wrote:
> [ . . . ]
>> print foo, bar -> print("%s %s" % (foo, bar))
> [ . . . ]
>
> Just to protect against creation of misinformation:
>
>
> print foo , bar  ->  print ( foo , bar )
>
> Also the "%s" and % operator are deprecated in Python 3, so:
>
> print ( "%s %s" % ( foo , bar ) ) -> print ( "{} {}".format ( foo ,
> bar ) )

Oh yes; still, in 3.1 they still work, which is good enough for now :).

> except Foo , e : ->  except Foo as e :

working$ python2.5
Python 2.5.5 (r255:77872, Jan 31 2010, 21:34:29)
[GCC 4.4.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> try:
...   1/0
... except Exception as e:
<stdin>:3: Warning: 'as' will become a reserved keyword in Python 2.6
  File "<stdin>", line 3
    except Exception as e:
                      ^
SyntaxError: invalid syntax


> I find that the following document is very helpful:
>
> http://ptgmedia.pearsoncmg.com/imprint_downloads/informit/promotions/python/python2python3.pdf

Thanks.

-Rob



More information about the bazaar mailing list