Python 2.5 in beta

Somewhere in August is expected the stable release of Python 2.5. This version has some additions that I welcome:
  • The excellent sqlite3 library is included as standard (called pysqlite). Sqlite is a great, SQL database that supports a great deal of the SQL92 standard (more than many commercial databases). It's nice that it'll be available for any Python installation and should introduce beginners with some good SQL practices. Also, the database is very fast and uses only one file. Programs like Amarok use SQLite. The only problem I've experience with SQLite is it's lack of backwards compatibility. I you point a pysqlite3 program to a sqlite2 database it'll just complain.
  • ElementTree, this is a great library and it's great that it's part of the standard distribution. The C version is particularly fast and uses very little memory. What makes this library so great is that it's very intuitive and has read/write access. For some projects I was using the harder to use DOM libraries only because they come standard with Python.
  • Generators (which are already great) become even more powerful (especially with the send() command). Generators now become coroutines, a more generalized form of subroutines.
  • Something that looks like a lot like closures but is called "Partial Function Application" is now available. In a nutshell, you can create function pointers with parameters already set. PEP 309
  • nlargest() function which help in returning the top-N elements, efficiently (using the heap data structure) - occasionally useful.
  • The WSGI reference package is added. You can create a simple web server program using this framework, and the code should be compatible when you change to a better web development framework. This might encourage more people to use Python for web development, a developer can write a program and try different backends.
  • Inline conditional expressions allow you to write the C expression "a = (x >= 0) ? x : -x;" as "a = x if x > 0 else -x". The order is a bit different but it's quite readable. I gather this is going to be used a lot and force a lot of people to install Python 2.5 because new code won't work with 2.4 anymore.
  • The 'with' statement doesn't look at all like the with statement in Visual Basic. With 'with' you can create an object that automatically does something when it leaves a block. If it leaves the block by an exception you also get a chance to do that something and you can find out what the exception was. This is great for locks, semaphores, file handles, mouse cursors or any object you want to be able to cleanup.
  • dict class can return a default value instead of throwing and exception - could be very useful - for example if the object isn't found in memory, you grab it from the database, for example.
  • startswith() and endswith() string method can take a bunch of strings to search for.
  • any() and all() methods added. For example "all([x, y, z])" is equivalent of trying "x or y or z". Lisp people will appreciate this.
Overall, I really like this new version of Python. The major new additions are the 'with' statement and inline conditional expressions. The addition of the new common libraries (ElementTree and SQLite) as part of the standard is a welcome addition.

p.s. sorry if you got this post multiple times, I keep hitting Ctrl-S which now posts in Blogger.

Comments

Popular posts from this blog

Shortest Sudoku solver in Python

Seven Segment Display in Inkscape

Dot to Png