Moving from Python 2 to Python 3: A 4 page "cheat sheet"

Mark Summerfield list at qtrac.plus.com
Wed Dec 2 11:03:27 EST 2009


On Dec 2, 11:20 am, Wolodja Wentland <wentl... at cl.uni-heidelberg.de>
wrote:
> On Wed, Dec 02, 2009 at 00:10 -0800, Mark Summerfield wrote:
> > On 1 Dec, 18:30, Lie Ryan <lie.1... at gmail.com> wrote:
> > > Also, I'm not sure what this change is referring to:
> > > Python 2                 Python 3
> > > L = list(seq)            L = sorted(seq)
> > > L.sort()
>
> > > L.sort is still available in python, and sorted() have been available
> > > since python 2. Both list.sort() and sorted() are for different purpose,
> > > and neither will be deprecated. What's the change here?
>
> > The document is about idioms as well as changes. In this case both
> > approaches work in both versions, but it seems that there are still a
> > lot of people who don't know about sorted(), so I put it in to show it
> > as an idiom.
>
> It would be quite nice if you could mark all the Python 3 idioms that
> work in Python 2.X as well. This would allow readers that are still using
> Python 2.X and are used to the 'old way' to adapt their coding style
> accordingly. You could just add a little (2.X) after the idiom for
> example.

Yes it would be nice, but it isn't quite so simple. To take sorted()
as just one example, it was introduced in 2.4 so arguably using it
isn't valid/idiomatic for Python 2.x programs where you care about
backwards compatibility for the Python 2.x series... But my main
reason for not wanting to do this is that the document is aimed at
people who want to write Python 3, not to encourage people to stick
with 2:-)

>
> And thanks for the nice cheat sheet! :-D

Thanks!

> --
>   .''`.     Wolodja Wentland    <wentl... at cl.uni-heidelberg.de>
>  : :'  :    
>  `. `'`     4096R/CAF14EFC
>    `-       081C B7CD FF04 2BA9 94EA  36B2 8B7F 7D30 CAF1 4EFC
>
>  signature.asc
> < 1KViewDownload




More information about the Python-list mailing list