subtle error slows code by 10x (builtin sum()) - replace builtin sum without using import?

Albert Hopkins marduk at
Sat Jul 2 04:54:10 CEST 2011

On Friday, July 1 at 19:17 (-0700), bdb112 said:

> Question:
> Can I replace the builtin sum function globally for test purposes so
> that my large set of codes uses the replacement?
> The replacement would simply issue warnings.warn() if it detected an
> ndarray argument, then call the original sum
> I could then find the offending code and use the appropriate import to
> get numpy.sum

You shouldn't do this, but you could use the __builtins__ module


>>> __builtins__.sum = numpy.sum # bad

More information about the Python-list mailing list