Learning Python now coming from Perl

J. Cliff Dyer jcd at sdf.lonestar.org
Tue Dec 9 16:01:07 CET 2008

On Sun, 2008-12-07 at 11:05 +0900, Bertilo Wennergren wrote:
> Aahz wrote:
> > In article <ghe0jo$3i1$1 at news.motzarella.org>,
> > Bertilo Wennergren  <bertilow at gmail.com> wrote:
> >> I don't suppose there is any introductory material out there that is
> >> based on Python 3000 and that is also geared at people with a Perl
> >> background? Too early for that I guess..
> > Honestly, the differences between 2.x and 3.0 are small enough that it
> > doesn't much matter, as long as you're not the kind of person who gets
> > put off by little problems.  Because so much material is for 2.x, you
> > may be better off just learning 2.x first and then moving to 3.x.
> The main reason I waited until Python 3000 came out is
> the new way Unicode is handled. The old way seemed really
> broken to me. Much of what I do when I program consists
> of juggling Unicode text (real Unicode text with lots of
> actual characters outside of Latin 1). So in my case
> learning version 2.x first might not be very convenient.
> I'd just get bogged down with the strange way 2.x handles
> such data. I'd rather skip that completely and just go
> with the Unicode handling in 3.0.

I've actually found python's unicode handling quite strong.  I will
grant that it is not intuitive, but once you have learned it, it is
clear, comprehensive, and sensible.  It is by no means broken, or
half-heartedly supported.  The drawback is that you have to explicitly
use it.  It doesn't happen by default.  

For starters, only using str objects for input and output.  As soon as
you get them, decode them to unicode.  And at the last minute, when
writing them, encode them to your favorite encoding.  Better yet, use
codecs.open(file, encoding='utf-16') in place of open(file), pass an
encoding argument, and be done with it.

When you create strings in your code, always use u'stuff' rather than
'stuff' and ur'stu\ff' rather than r'stu\ff'.

If you work with unicode on a daily basis, it shouldn't be hard to
master.  There are several good tutorials on the web.


More information about the Python-list mailing list