Saturday, September 29, 2012

Python 3.3 is my Favorite Python Release

Today, Python 3.3 was released. During the 4.5 years I've been a CPython core developer, 6 major Python releases (2.6, 2.7, 3.0, 3.1, 3.2, and 3.3) have past by me. In this post, I will explain why 3.3 is the most exciting Python release to me. I will be cherrypicking, consult "What's New in Python 3.3" and the Misc/NEWS file for complete details.


PEP 393 completely changed the internal format of Python's Unicode implementation. It does away with the concept of wide and narrow unicode builds. The encoding of a string now depends on its maximum codepoint; there are 1-byte, 2-byte, or 4-byte strings internally. This means, for example, that strings with only ASCII characters can be represented in their most compact format. Partially as a consequence, Unicode standard compilance has improved. Indexing strings always gives code points not surrogates like on < 3.3 narrow builds. str.lower(), str.upper(), and str.title() have been fixed to use full Unicode case-mappings instead of the simple 1-1 ones. The str.casefold method implements the Unicode casefolding algorithm.
If the gods of PyCon talk selection smile on me, I will be giving a talk about this and the history of Unicode in Python.

Glorious Return of the "u" Prefix

Python 3.3 allows the u in front of strings again. Since the b prefix is supported from Python 2.6, code which wants to support 2.x and 3.3 shouldn't need to use unpleasant kludges like six's u() and b() functions. I don't think it would be unreasonable for libraries to only support 2.7 and 3.3+ now just to have the more natural string syntaxes.

Many Nice Things

One of the annoyances in previous Python 3 versions was it was impossible to turn off PEP 3134's implicit exception chaining. The raise exc from None syntax introduced in 3.3 prevents the __context__ of an exception from being printed.
There were improvements in exceptions themselves. PEP 3151 merged IOError, OSError, WindowsError, and various error types in the standard library. It also created a hierarchy of specialized exception subclasses. This means that most code dealing with IO errors won't have to dig into the errno module. For example, this standard pattern
    fp = open("data", "rb")
except OSError as e:
    if e.errno != errno.ENOENT:
    # Create file
can become
    fp = open("data", "rb")
except FileNotFoundError:
    # Create file
. (Of course, for this sort of thing you can also use the new "x" mode in open().) The errors from incorrect call signatures have improved:
Python 3.3.0+ (3.3:7e83c8ccb1ba, Sep 29 2012, 10:34:54) 
[GCC 4.5.4] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> def f(a, b, c=5, *, kw1, kw2): pass
>>> f(1, kw2=42)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: f() missing 1 required positional argument: 'b'
>>> f(1, 2, kw2=42)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: f() missing 1 required keyword-only argument: 'kw1'
In the future, I think there should be a ArgumentsError subclass of TypeError which provides programmatic access to the signature mismatch, but this is a start. The new standard library modules, ipaddress, lzma, a dn unittest.mock are certainly worth a look.
The Windows installer has an option to set up PATH for you.


Unknown said...

Thanks for the ideas. I have a consulting business site named Hong Kong Compliance

MS Dynamics said...

It was a great information and Its really worth reading it.
Python Online Training in Hyderabad

Python Institute in Hyderabad

Python Course in Hyderabad

Sahithya said...

Enroll today to get free access to our live demo session which is a great opportunity to interact with the trainer directly which is a placement based Salesforce training India with job placement and certification . Get salesforce training in affordable cost from a best computer institute.

Bhanu Sree said...

Thank you for sharing the wonderful information with us to get some ideas about it.

Python Training in Hyderabad
Python Training
Python Online Training
Python Course in Hyderabad
Python Institute in Hyderabad
Python Online Training in Hyderabad

Aptron Gurgaon said...

Thanks for sharing this Information. Python Training Course in Gurgaon

coMakeIT said...

Nice Post Product Engineering Company in UK

rstrainings said...

I really loved reading through this article... Thanks for sharing such an amazing post with us and keep blogging...

AchieversIT said...

Really nice and informative blog, keep it up. Thanks for sharing and I have some suggestions.
if you want to learn pyhton Programming, Join Now Python Training in Bangalore.
Here is a Website- Software Training in Bangalore | AchieversIT
This may help you to find something useful

AchieversIT said...

Thank you for your blog , it was usefull and informative "AchieversIT is the best Training institute for angular training. angular training in bangalore "

BCA Jamnagar said...

How to add two numbers entered by the user in #python | #bcaschool

How to #add two #numbers in #python | #addition in #python | BCA School said...

how to buy psychedelic product

Buy DMT crystal online

Buy LSD gel tabs here

Buy lsd blotters strains here

Buy ketamine crystal here

Buy magic mushrooom strains here

Buy quality mushroom, GT here

Buy DMT vape pen here

Buy mushroom chocolate bars here

Raj Sharma said...

Python Training in Noida

Lorriel Sims said...

An exceptionally popular programming language that is being used officially by a vast majority of organizations as their primary in stucco repair boca raton

Valentino Kuburovic said...

Thanks, buy canik guns canik gun dealers
Thanks benelli firearms guns benelli firearms 
ruger gun  ruger gun dealers
colt guns colt gun dealers
beretta firearms beretta guns
taurus judge guns taurus judge guns 
disket online apotek  diskret online apotek stadsapotek stads apotek 
scandinavia apotek  apotek 
fire arms store  fire arms store

Ramesh Sampangi said...

Thanks for sharing such awesome information, If anyone is interested in Python Click here, Python Course in Hyderabad

Keerthi55 said...

python online training in hyderabad
python online training hyderabad

Innomatics said...

Become a Data Science expert with us. study Data Science Course in Hyderabad with Innomatics where you get a great experience and better knowledge.

Unknown said...

Nice article and great explanation about Python coding. Keep up the good work and Python training is the best one to get the job as a fresher and Data Science course is the added advantage.

Technokryon said...

Thanks for sharing the valuable information here. Keep sharing more informative articles. Regards by technokryon

hire python developer india
best data science companies
professional cloud devops engineer

technologyforall said...

Best Online Data Science Course course training with job assistance and internship opportunities .At ‘Technology For All’, we believe in sharing knowledge. Our focus is not just on teaching but involving you in each aspect of learning. With us, you get an opportunity to innovate on projects, work on case studies, gain quality industry knowledge, professional perspective and become job-ready.

Innomatics said...

Become a Data Science expert with Innomatics. we provide classroom training on Data Science course in Hyderabad for the individuals who believe hand-held training. We teach as per the Indian Standard Time (IST) with In-depth practical Knowledge on each topic in classroom training, 80 – 90 Hrs of Real-time practical training classes. There are different slots available on weekends or weekdays according to your choices.