backport of 'set' to python 2.3?

Ben Finney bignose+hates-spam at benfinney.id.au
Wed May 21 21:54:42 EDT 2008


"Daniel Fetchinson" <fetchinson at googlemail.com> writes:

> Does anyone have a pure python implementation of the builtin 'set'
> object so that I could use that in python 2.3?

Yes. You have one in Python 2.3 already
<URL:http://www.python.org/doc/2.3.5/lib/module-sets.html>, it's just
not a builtin.

> If this would be the case that would be really great as I wouldn't
> have to change my code that runs happily on 2.5

You will, but it's as simple as:

    try:
        set()
    except NameError:
        from sets import Set as set

You then know that 'set' refers to the set type from that point on (or
you're not on a version of Python that has a 'set' type at all).

-- 
 \      "I have a large seashell collection, which I keep scattered on |
  `\        the beaches all over the world. Maybe you've seen it."  -- |
_o__)                                                    Steven Wright |
Ben Finney



More information about the Python-list mailing list