views:

455

answers:

4

A lot of useful features in Python are somewhat "hidden" inside modules. Named tuples (new in Python 2.6), for instance, are found in the collections module.

The Library Documentation page will give you all the modules in the language, but newcomers to Python are likely to find themselves saying "Oh, I didn't know I could have done it this way using Python!" unless the important features in the language are pointed out by the experienced developers.

I'm not specifically looking for new modules in Python 2.6, but modules that can be found in this latest release.

+5  A: 

May be PEP 0631 and What's new in 2.6 can provide elements of answer. This last article explains the new features in Python 2.6, released on October 1 2008.

David Segonds
+11  A: 

The most impressive new module is probably the multiprocessing module. First because it lets you execute functions in new processes just as easily and with roughly the same API as you would with the threading module. But more importantly because it introduces a lot of great classes for communicating between processes, such as a Queue class and a Lock class which are each used just like those objects would be in multithreaded code, as well as some other classes for sharing memory between processes.

You can find the documentation at http://docs.python.org/library/multiprocessing.html

Eli Courtwright
+5  A: 

The new json module is a real boon to web programmers!! (It was known as simplejson before being merged into the standard library.)

It's ridiculously easy to use: json.dumps(obj) encodes a built-in-type Python object to a JSON string, while json.loads(string) decodes a JSON string into a Python object.

Really really handy.

Dan
+2  A: 

Essential Libraries

The main challenge for an experienced programmer coming from another language to Python is figuring out how one language maps to another. Here are a few essential libraries and how they relate to Java equivalents.

os, os.path

Has functionality like in java.io.File, java.lang.Process, and others. But cleaner and more sophisticated, with a Unix flavor. Use os.path instead of os for higher-level functionality.

sys

Manipulate the sys.path (which is like the classpath), register exit handlers (like in java Runtime object), and access the standard I/O streams, as in java.lang.System.

unittest

Very similar (and based on) jUnit, with test fixtures and runnable harnesses.

logging

Functionality almost identical to log4j with loglevels and loggers. ( logging is also in the standard java.util.Logging library)

datetime

Allows parsing and formatting dates and times, like in java.text.DateFormat, java.util.Date and related.

ConfigParser

Allows persistant configuration as in a java Properties file (but also allows nesting). Use this when you don't want the complexity of XML or a database backend.

socket, urllib

Similar functionality to what is in java.net, for working with either sockets, or retrieving content via URLs/URIs.

Also, keep in mind that a lot of basic functionality, such as reading files, and working with collections, is in the core python language, whereas in Java it lives in packages.

Dutch Masters