Attribute error using __builtin__ functions inside class method
Question: I installed rdiff-backup on my arch linux box only to end up with the
attribute error:

    
    
    AttributeError: 'module' object has no attribute 'reduce'
    

The error exists in one of rdiff_backup classes, but I can not spot the error.
The function `reduce` should be builtin, and I can not get the code to find
the function.

The code from rdiff looks like this:

    
    
        def get_total_dest_size_change(self):
            """Return total destination size change
    
            This represents the total change in the size of the
            rdiff-backup destination directory.
    
            """
            addvals = [self.NewFileSize, self.ChangedSourceSize,
                               self.IncrementFileSize]
            subtractvals = [self.DeletedFileSize, self.ChangedMirrorSize]
            for val in addvals + subtractvals:
                    if val is None:
                            result = None
                            break
            else:
                    def addlist(l): return reduce(lambda x,y: x+y, l)
                    result = addlist(addvals) - addlist(subtractvals)
            self.TotalDestinationSizeChange = result
            return result
    

And the error occurs in the locally defined addlist function. I've tried to
import the builtin module in the top of the file (statistics.py), both like

    
    
    import __builtin__
    

and

    
    
    from __builtin__ import reduce
    

and tried to change the namespace of the method like so:

    
    
    def addlist(l): return __builtin__.reduce(lambda x,y: x+y, l)
    

But alas. Still the same error.

I've not been able to find any good information or solution so far, so maybe
someone with a little tighter knowledge about python could take stab at it.

Thanks m


Answer: `reduce(lambda x,y: x+y, l)` is an equivalent of `sum(l)`. Can you try whether
`sum(l)` works? Also, which python version are you using (`sum` is available
in version >= 2.3)

