Jeff Spaleta wrote:
On Fri, May 1, 2009 at 12:06 PM, Jeff Spaleta
<jspaleta(a)gmail.com> wrote:
> On Fri, May 1, 2009 at 12:03 PM, Jeff Spaleta <jspaleta(a)gmail.com> wrote:
>> On Fri, May 1, 2009 at 11:57 AM, David Malcolm <dmalcolm(a)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=rev...
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