weakref — Impermanent References to Objects — PyMOTW 3

The weakref module supports weak references to objects. A normal reference increments the reference count on the object and prevents it from being garbage collected. This is not always desirable, either when a circular reference might be present or when building a cache of objects that should be deleted when memory is needed. A weak reference is a handle to an object that does not keep it from being cleaned up automatically.

Read more…

This post is part of the Python Module of the Week series for Python 3. See PyMOTW.com for more articles from the series.

locale — Cultural Localization API — PyMOTW 3

The locale module is part of Python’s internationalization and localization support library. It provides a standard way to handle operations that may depend on the language or location of a user. For example, it handles formatting numbers as currency, comparing strings for sorting, and working with dates. It does not cover translation (see the gettext module) or Unicode encoding (see the codecs module).

Read more…

This post is part of the Python Module of the Week series for Python 3. See PyMOTW.com for more articles from the series.

heapq – Heap Sort Algorithm — PyMOTW 3

A heap is a tree-like data structure where the child nodes have a sort-order relationship with the parents. Binary heaps can be represented using a list or array organized so that the children of element N are at positions 2*N+1 and 2*N+2 (for zero-based indexes). This layout makes it possible to rearrange heaps in place, so it is not necessary to reallocate as much memory when adding or removing items.

Read more…

This post is part of the Python Module of the Week series for Python 3. See PyMOTW.com for more articles from the series.

operator — Functional Interface to Built-in Operators — PyMOTW 3

Programming using iterators occasionally requires creating small functions for simple expressions. Sometimes, these can be implemented as lambda functions, but for some operations new functions are not needed at all. The operator module defines functions that correspond to built-in operations for arithmetic, comparison, and other operations corresponding to standard object APIs.

Read more…

This post is part of the Python Module of the Week series for Python 3. See PyMOTW.com for more articles from the series.

pickle — Object Serialization — PyMOTW 3

The pickle module implements an algorithm for turning an arbitrary Python object into a series of bytes. This process is also called serializing the object. The byte stream representing the object can then be transmitted or stored, and later reconstructed to create a new object with the same characteristics.

Read more…

This post is part of the Python Module of the Week series for Python 3. See PyMOTW.com for more articles from the series.

uuid — Universally Unique Identifiers — PyMOTW 3

RFC 4122 defines a system for creating universally unique identifiers for resources in a way that does not require a central registrar. UUID values are 128 bits long and, as the reference guide says, “can guarantee uniqueness across space and time.” They are useful for generating identifiers for documents, hosts, application clients, and other situations where a unique value is necessary. The RFC is specifically focused on creating a Uniform Resource Name namespace and covers three main algorithms:

Read more…

This post is part of the Python Module of the Week series for Python 3. See PyMOTW.com for more articles from the series.