weakrefset 1.0.0
A WeakSet class for storing objects using weak references.
Python 2.7 & 3.1 include a WeakSet class, a collection for storing objects using weak references (see the Python weakref module).
This project is a backport of the weakrefset module, and tests, for Python 2.5 and 2.6. The tests require the unittest2 package.
- Mercurial repository & issue tracker: http://code.google.com/p/weakrefset/
You can install it with: pip install weakrefset
Usage is straightforward. You don't need to deal with weak references themselves, the WeakSet manages the references and you can add / remove / iterate over your objects directly:
>>> from weakrefset import WeakSet >>> class Foo(object): pass ... >>> f1 = Foo() >>> f2 = Foo() >>> refs = WeakSet([f1, f2]) >>> f3 = Foo() >>> refs.add(f3) >>> refs.remove(f1) >>> del f2 >>> f3 in refs True >>> for f in refs: ... print f ... <__main__.Foo object at 0x40e410>
To be compatible with Python 2.5, 2.6 and future versions of Python you can import it like this:
try:
# location in Python 2.7 and 3.1
from weakref import WeakSet
except ImportError:
# separately installed
from weakrefset import WeakSet
| File | Type | Py Version | Uploaded on | Size | # downloads |
|---|---|---|---|---|---|
| weakrefset-1.0.0.tar.gz (md5) | Source | 2010-03-30 | 2KB | 1162 | |
- Author: Michael Foord
- Home Page: http://pypi.python.org/pypi/weakrefset
- Keywords: weakref set collection
-
Categories
- Development Status :: 5 - Production/Stable
- Environment :: Console
- Intended Audience :: Developers
- License :: OSI Approved :: BSD License
- Operating System :: OS Independent
- Programming Language :: Python
- Programming Language :: Python :: 2.5
- Programming Language :: Python :: 2.6
- Topic :: Software Development :: Libraries
- Topic :: Software Development :: Libraries :: Python Modules
- Package Index Owner: Fuzzyman
- DOAP record: weakrefset-1.0.0.xml
