The logging module defines a standard API for reporting errors and status information from all of your modules. The key benefit of having the logging API provided by a standard library module is that all python modules can participate in logging, so your application log can include messages from third-party modules.
Read more at pymotw.com: logging
A little over a week ago I received a review copy of Sylvain Hellegouarch’s new book, CherryPy Essentials, published through Packt Publishing. The timing couldn’t have been better, since we have begun investigating Python web application frameworks at work for a new project. From previous work I have done with TurboGears, I knew that CherryPy was a contender, so I was definitely interested to see what version 3 had to offer.
Back in January I described an idea for a site to build network graphs of people in public life. It looks like unfluence is doing something like what I envisioned, automatically. The data is based on state campaign donations from the National Institute on Money in Politics.
Oh, and it sounds like they are planning to release the source in some form, too.
The bisect module implements an algorithm for inserting elements into a list while maintaining the list in sorted order. This can be much more efficient than repeatedly sorting a list, or explicitly sorting a large list after it is constructed.
Read more at pymotw.com: bisect
The linecache module is used extensively throughout the Python standard library when dealing with Python source files. The implementation of the cache simply holds the contents of files, parsed into separate lines, in a dictionary in memory. The API returns the requested line(s) by indexing into a list. The time savings is from (repeatedly) reading the file and parsing lines to find the one desired. This is especially useful when looking for multiple lines from the same file, such as when producing a traceback for an error report.
I just posted a new version of my codehosting project for django which supports passing the Atom feeds for release updates through feedburner.com. There isn’t anything tying the implementation to FeedBurner, of course, but since that’s why I wanted the feature that’s how I am describing it.
One tricky bit was I wanted all of the existing subscribers to my feed(s) to be redirected to the FeedBurner URL. I couldn’t just add a redirect rule in Apache, since not all of the feeds are set up with FeedBurner yet.
The textwrap module can be used to format text for output in situations where pretty-printing is desired. It offers programmatic functionality similar to the paragraph wrapping or filling features found in many text editors.
Read more at pymotw.com: textwrap
The StringIO class provides a convenient means of working with text in-memory using the file API (read, write. etc.). There are 2 separate implementations. The cStringIO module is written in C for speed, while the StringIO module is written in Python for portability. Using cStringIO to build large strings can offer performance savings over some other string conctatenation techniques.
Read more at pymotw.com: StringIO
The Queue module provides a FIFO implementation suitable for multi-threaded programming. It can be used to pass messages or other data between producer and consumer threads safely. Locking is handled for the caller, so it is simple to have as many threads as you want working with the same Queue instance. A Queue’s size (number of elements) may be restricted to throttle memory usage or processing.
Read more at pymotw.com: Queue