Is there a way to customise math.sqrt(x) for some x?

Nobody nobody at nowhere.com
Sat Jul 16 09:42:38 EDT 2011


On Sat, 16 Jul 2011 19:14:47 +1000, Chris Angelico wrote:

> Only thing I can think of is:
> 
> import math
> math.sqrt=lambda(x) x.__sqrt__(x) if x.whatever else math.sqrt(x)

math.sqrt=(lambda sqrt=math.sqrt: lambda x: x.__sqrt__(x) if hasattr(x,'__sqrt__') else sqrt(x))()




More information about the Python-list mailing list