Can anyone volunteer to help with a Python 2.5 / Python 2.4 code issue?

Toshio Kuratomi a.badger at gmail.com
Fri May 1 20:23:26 UTC 2009


Jeff Spaleta wrote:
> On Fri, May 1, 2009 at 12:06 PM, Jeff Spaleta <jspaleta at gmail.com> wrote:
>> On Fri, May 1, 2009 at 12:03 PM, Jeff Spaleta <jspaleta at gmail.com> wrote:
>>> On Fri, May 1, 2009 at 11:57 AM, David Malcolm <dmalcolm at redhat.com> wrote:
>>>> So where's the 2.5-only code?
>>> Im getting python import errors trying to use the triager link off the
>>> main page when running on Centos  no such error running under Fedora
>>> 9.  Something's different. But I need more background on the problem.
>>
>> Collections module in python 2.5 does not define a defaultdict class.
>>
>> That's the first problem
> 
> 
> Err reverse that.. python 2.4 no defaultdict class  in collections
> module python 2.5 collections does have it
> 
Yeah, defaultdict is useful but not in python-2.4.

Python-2.4 does have "setdefault" which is a misleading name (it doesn't
"set" a "default") for something that can be made to replace defaultdict
sometimes.

Here's an example of making a replacement in python-fedora:
http://bzr.fedorahosted.org/bzr/python-fedora-python-fedora-devel?cmd=revision;rev=397

Usually, if I was going to rewrite some code, I'd use a try: except: as
it's clearer what's going on.  Here's an example:

variable = {}
for key, index, data in [('one', 'a', '1'), ('two', 'b', 2), ('two',
'c', 3)]:
    try:
        variable[key][index] = data
    except KeyError:
   variable[key] = {index: data}

-Toshio

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 197 bytes
Desc: OpenPGP digital signature
URL: <http://listman.redhat.com/archives/fedora-python-devel-list/attachments/20090501/1937448f/attachment.sig>


More information about the Fedora-python-devel-list mailing list