Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Moving from Python 2 to Python 3: A 4 page "cheat sheet"

Reply
Thread Tools

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

 
 
Mark Summerfield
Guest
Posts: n/a
 
      12-01-2009
I've produced a 4 page document that provides a very concise summary
of Python 2<->3 differences plus the most commonly used new Python 3
features. It is aimed at existing Python 2 programmers who want to
start writing Python 3 programs and want to use Python 3 idioms rather
than those from Python 2 where the idioms differ.

It uses Python 3.1 syntax since that looks like being the standard for
a few years in view of the language moratorium.

The document is U.S. Letter size but will also print fine on A4
printers.

It is available as a free PDF download (no registration or anything)
from InformIT's website. Here's the direct link:
http://ptgmedia.pearsoncmg.com/impri...on2python3.pdf

And of course, if you want more on Python 3, there's always the
documentation---or my book
"Programming in Python 3 (Second Edition)" ISBN-10: 0321680561.
 
Reply With Quote
 
 
 
 
Daniel Fetchinson
Guest
Posts: n/a
 
      12-01-2009
> I've produced a 4 page document that provides a very concise summary
> of Python 2<->3 differences plus the most commonly used new Python 3
> features. It is aimed at existing Python 2 programmers who want to
> start writing Python 3 programs and want to use Python 3 idioms rather
> than those from Python 2 where the idioms differ.
>
> It uses Python 3.1 syntax since that looks like being the standard for
> a few years in view of the language moratorium.


This really looks very useful, thanks a lot!
I've been wishing something like this existed for a while, really handy.

Cheers,
Daniel



--
Psss, psss, put it down! - http://www.cafepress.com/putitdown
 
Reply With Quote
 
 
 
 
Gnarlodious
Guest
Posts: n/a
 
      12-01-2009
On Dec 1, 7:03*am, Mark Summerfield wrote:

> "Programming in Python 3 (Second Edition)" ISBN-10: 0321680561.


I ordered it...

-- Gnarlie
http://Gnarlodious.com
 
Reply With Quote
 
Mark Dickinson
Guest
Posts: n/a
 
      12-01-2009
On Dec 1, 2:03*pm, Mark Summerfield <(E-Mail Removed)> wrote:
> I've produced a 4 page document that provides a very concise summary
> of Python 2<->3 differences plus the most commonly used new Python 3
> features.


Very nice indeed!

My only quibble is with the statement on the first page that
the 'String % operator is deprecated'. I'm not sure that's
true, for all values of 'deprecated'. There don't appear
to be any definite plans for getting rid of it just yet.

Mark
 
Reply With Quote
 
Lie Ryan
Guest
Posts: n/a
 
      12-01-2009
On 12/2/2009 1:03 AM, Mark Summerfield wrote:
> I've produced a 4 page document that provides a very concise summary
> of Python 2<->3 differences plus the most commonly used new Python 3
> features. It is aimed at existing Python 2 programmers who want to
> start writing Python 3 programs and want to use Python 3 idioms rather
> than those from Python 2 where the idioms differ.
>
> It uses Python 3.1 syntax since that looks like being the standard for
> a few years in view of the language moratorium.
>
> The document is U.S. Letter size but will also print fine on A4
> printers.
>
> It is available as a free PDF download (no registration or anything)
> from InformIT's website. Here's the direct link:
> http://ptgmedia.pearsoncmg.com/impri...on2python3.pdf
>
> And of course, if you want more on Python 3, there's always the
> documentation---or my book
> "Programming in Python 3 (Second Edition)" ISBN-10: 0321680561.


Nice.

I suggest changing the lambda example a bit, the current example says:
Python 2 Python 3
lambda (a,b): a + b lambda t: t[0] + t[1]
lambda a, b: a + b

into something like:

Python 2 Python 3
lambda (a,b),c: a + b + c lambda t, c: t[0] + t[1] + c
lambda a, b, c: a + b + c

it is unclear at first sight that it refers to tuple argument unpacking.
There should also some mention that tuple argument unpacking for regular
function (def) is also gone.



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?

 
Reply With Quote
 
Terry Reedy
Guest
Posts: n/a
 
      12-01-2009
Mark Summerfield wrote:
> I've produced a 4 page document that provides a very concise summary
> of Python 2<->3 differences plus the most commonly used new Python 3
> features. It is aimed at existing Python 2 programmers who want to
> start writing Python 3 programs and want to use Python 3 idioms rather
> than those from Python 2 where the idioms differ.
>
> It uses Python 3.1 syntax since that looks like being the standard for
> a few years in view of the language moratorium.
>
> The document is U.S. Letter size but will also print fine on A4
> printers.
>
> It is available as a free PDF download (no registration or anything)
> from InformIT's website. Here's the direct link:
> http://ptgmedia.pearsoncmg.com/impri...on2python3.pdf
>
> And of course, if you want more on Python 3, there's always the
> documentation---or my book
> "Programming in Python 3 (Second Edition)" ISBN-10: 0321680561.


What might be even *more* helpful, with contributions from others
perhaps, would be an indication of which changes are handled
automatically by 2to3.py and which must be done by hand.

tjr

 
Reply With Quote
 
John Bokma
Guest
Posts: n/a
 
      12-01-2009
Mark Summerfield <(E-Mail Removed)> writes:

> It is available as a free PDF download (no registration or anything)
> from InformIT's website. Here's the direct link:
> http://ptgmedia.pearsoncmg.com/impri...on2python3.pdf


Thanks!

> And of course, if you want more on Python 3, there's always the
> documentation---or my book
> "Programming in Python 3 (Second Edition)" ISBN-10: 0321680561.


Meh, second edition already? Haven't read the entire first edition
yet. Which is IMO a good book (I also gave it to my brother as a
present).

Only negative point (to me) so far is that in the beginning (p8-9) the
book mentions placing Python programs in C:\py3eg which gives me the
unpleasant feeling that someone is coding on Windows XP with
Administrator rights...

Anyway, will add the 2nd edition to my wish list and donate the current
one to the library in Xalapa (USBI) if they want it

John

 
Reply With Quote
 
Mark Summerfield
Guest
Posts: n/a
 
      12-02-2009
On 1 Dec, 17:50, Mark Dickinson <(E-Mail Removed)> wrote:
> On Dec 1, 2:03*pm, Mark Summerfield <(E-Mail Removed)> wrote:
>
> > I've produced a 4 page document that provides a very concise summary
> > of Python 2<->3 differences plus the most commonly used new Python 3
> > features.

>
> Very nice indeed!
>
> My only quibble is with the statement on the first page that
> the 'String % operator is deprecated'. *I'm not sure that's
> true, for all values of 'deprecated'. *There don't appear
> to be any definite plans for getting rid of it just yet.
>
> Mark


I didn't make this up

According to http://docs.python.org/dev/3.0/whatsnew/3.0.html
"The plan is to eventually make this the only API for string
formatting, and to start deprecating the % operator in Python 3.1."
 
Reply With Quote
 
Mark Summerfield
Guest
Posts: n/a
 
      12-02-2009
On 1 Dec, 18:30, Lie Ryan <(E-Mail Removed)> wrote:
> On 12/2/2009 1:03 AM, Mark Summerfield wrote:
>
>
>
> > I've produced a 4 page document that provides a very concise summary
> > of Python 2<->3 differences plus the most commonly used new Python 3
> > features. It is aimed at existing Python 2 programmers who want to
> > start writing Python 3 programs and want to use Python 3 idioms rather
> > than those from Python 2 where the idioms differ.

>
> > It uses Python 3.1 syntax since that looks like being the standard for
> > a few years in view of the language moratorium.

>
> > The document is U.S. Letter size but will also print fine on A4
> > printers.

>
> > It is available as a free PDF download (no registration or anything)
> > from InformIT's website. Here's the direct link:
> >http://ptgmedia.pearsoncmg.com/impri...it/promotions/...

>
> > And of course, if you want more on Python 3, there's always the
> > documentation---or my book
> > "Programming in Python 3 (Second Edition)" ISBN-10: 0321680561.

>
> Nice.


Thanks!

> I suggest changing the lambda example a bit, the current example says:
> Python 2 * * * * * * * * * * *Python 3
> lambda (a,b): a + b * * * * * lambda t: t[0] + t[1]
> * * * * * * * * * * * * * * * *lambda a, b: a + b
>
> into something like:
>
> Python 2 * * * * * * * * * * *Python 3
> lambda (a,b),c: a + b + c * * lambda t, c: t[0] + t[1] + c
> * * * * * * * * * * * * * * * *lambda a, b, c: a + b + c
>
> it is unclear at first sight that it refers to tuple argument unpacking.


Your proposed example is clearer in some respects, but mine is more
minimal. And I think that anyone who _thinks_ about mine will get the
point. (The document is short, but I never claimed it was a quick
read

> There should also some mention that tuple argument unpacking for regular
> function (def) is also gone.


I probably should have, but it is hard to fit any more in... esp.
since I don't want to take anything out.

> 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.
 
Reply With Quote
 
Mark Summerfield
Guest
Posts: n/a
 
      12-02-2009
On 1 Dec, 21:55, Terry Reedy <(E-Mail Removed)> wrote:
> Mark Summerfield wrote:
> > I've produced a 4 page document that provides a very concise summary
> > of Python 2<->3 differences plus the most commonly used new Python 3
> > features. It is aimed at existing Python 2 programmers who want to
> > start writing Python 3 programs and want to use Python 3 idioms rather
> > than those from Python 2 where the idioms differ.

>
> > It uses Python 3.1 syntax since that looks like being the standard for
> > a few years in view of the language moratorium.

>
> > The document is U.S. Letter size but will also print fine on A4
> > printers.

>
> > It is available as a free PDF download (no registration or anything)
> > from InformIT's website. Here's the direct link:
> >http://ptgmedia.pearsoncmg.com/impri...it/promotions/...

>
> > And of course, if you want more on Python 3, there's always the
> > documentation---or my book
> > "Programming in Python 3 (Second Edition)" ISBN-10: 0321680561.

>
> What might be even *more* helpful, with contributions from others
> perhaps, would be an indication of which changes are handled
> automatically by 2to3.py and which must be done by hand.
>
> tjr


No, that's exactly what I did not want to cover and the document says
so up front. It is aimed at people who want Python 3 to come from
their own brains and fingers!

Also, the kind of info you're talking about is covered elsewhere, for
example:
http://diveintopython3.org/porting-c...with-2to3.html
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Moving Guide Moving Companies Movers Storage linkswanted ASP .Net 0 01-23-2008 01:08 AM
Free Moving Estimate, Local Movers, Long Distance Moving, PackingSupplies, Storage Rental, Home Moving, Apartment Moving, Office Moving,Commercial Moving linkswanted ASP .Net 0 01-06-2008 04:45 AM
Moving to California Moving to L.A linkswanted Digital Photography 3 01-05-2008 04:22 PM
movers los angeles moving storage services movers in L.A companymoving companies moving in calfornia los angeles linkswanted HTML 0 12-21-2007 10:55 PM



Advertisments