From: Mark Summerfield on
On Dec 2, 8:53 am, Mark Dickinson <dicki...(a)gmail.com> wrote:
> On Dec 2, 8:01 am, MarkSummerfield<l...(a)qtrac.plus.com> wrote:
>
> > On 1 Dec, 17:50, Mark Dickinson <dicki...(a)gmail.com> wrote:
> > > 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.
>
> > I didn't make this up:-)
>
> No, I didn't imagine for a second that you had!
>
> > According tohttp://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."
>
> I think that's a doc bug.  "The plan is to ..." should read: "The plan
> was
> originally to ...".  (Well, at least in the 3.1 version of the
> "what's new in 3.0" documentation;  the 3.0 version that you linked to
> isn't even autogenerated any more, AFAIK, so fixes to the ReST source
> for that file never make it to the web site.)
>
> I'm a little confused myself about what's actually happening with
> % formatting, but here's a fairly recent python-dev posting from
> the BDFL:
>
> http://mail.python.org/pipermail/python-dev/2009-September/092399.html

Well it seems clear to me that the BDFL wants to kill of % formatting,
but wasn't able to for Python 3... So I still think it is reasonable
(1) to describe it as deprecated and (2) to only teach and use
str.format().
From: Mark Summerfield on
On Dec 2, 11:20 am, Wolodja Wentland <wentl...(a)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...(a)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...(a)cl.uni-heidelberg.de>
>  : :'  :    
>  `. `'`     4096R/CAF14EFC
>    `-       081C B7CD FF04 2BA9 94EA  36B2 8B7F 7D30 CAF1 4EFC
>
>  signature.asc
> < 1KViewDownload

From: Mark Summerfield on
On Dec 2, 11:31 am, "Martin P. Hellwig" <martin.hell...(a)dcuktec.org>
wrote:
> MarkSummerfieldwrote:
>
> <cut>> 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/imprint_downloads/informit/promotions/...
>
> <cut>
> Very handy! Am I wrong in assuming that you forgot to include that
> file() is gone in favour of open()?

No you are not wrong in assuming that I forgot that:-(

My lame excuse is that file() was introduced for isinstance() testing
and similar, and never really as a replacement for open().

Anyway, I have now added:

fh = file(fname, mode) | fh = open(fname, mode)

I've sent a new PDF with this change to InformIT, so hopefully it'll
become available soon from
http://www.informit.com/promotions/promotion.aspx?promo=13751
From: Mark Summerfield on
On Dec 2, 4:22 pm, Mark Summerfield <l...(a)qtrac.plus.com> wrote:
> On Dec 2, 11:31 am, "Martin P. Hellwig" <martin.hell...(a)dcuktec.org>
> wrote:
>
> > MarkSummerfieldwrote:
>
> > <cut>> 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/imprint_downloads/informit/promotions/....
>
> > <cut>
> > Very handy! Am I wrong in assuming that you forgot to include that
> > file() is gone in favour of open()?
>
> No you are not wrong in assuming that I forgot that:-(
>
> My lame excuse is that file() was introduced for isinstance() testing
> and similar, and never really as a replacement for open().
>
> Anyway, I have now added:
>
>     fh = file(fname, mode) | fh = open(fname, mode)
>
> I've sent a new PDF with this change to InformIT, so hopefully it'll
> become available soon fromhttp://www.informit.com/promotions/promotion.aspx?promo=13751

Oops wrong URL again, should have been:
http://www.informit.com/promotions/promotion.aspx?promo=137519
.... time to go offline and sleep ...
From: John Posner on
On Wed, 02 Dec 2009 10:55:23 -0500, Mark Summerfield <list(a)qtrac.plus.com>
wrote:

> On Dec 1, 2:03 pm, Mark Summerfield <l...(a)qtrac.plus.com> 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.

Mark, I add my thanks to those of the other responders. If you find space,
you might consider adding another str.format() feature:

Goal: place integer 456 flush-right in a field of width 8

Py2: "%%%dd" % 8 % 456
Py3: "{0:{1}d}".format(456, 8)

With str.format(), you don't need to nest one formatting operation within
another. A little less mind-bending, and every little bit helps!

-John
First  |  Prev  |  Next  |  Last
Pages: 1 2 3 4 5 6 7 8
Prev: can you say it please
Next: can python do this?