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.

Unicode

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
try:
    fp = open("data", "rb")
except OSError as e:
    if e.errno != errno.ENOENT:
        raise
    # Create file
can become
try:
    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.







12 comments:

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

rstrainings said...

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


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 "

Unknown 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

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

Ramesh Sampangi said...

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

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.

Ramesh Sampangi said...

Become an expert in Data Science by joining AI Patasala Data Science Course I Hyderabad program, where you can gain practical knowledge from industry experts.
Data Science Course in Hyderabad

john NJL said...

buy mescalin-or-peyote online

buy mushroom-edibles online


buy Ayahuasca online

dmt-nn-dimethyltryptamine for sale


iboga for sale


ketamine for sale

krantom for sale

lsd-lysergic-acid-diethylamide


psylocybins-magic-mushrooms
https://hippiestore.org/