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

Gary Herron gherron at islandtraining.com
Sat Jul 16 11:56:44 EDT 2011


On 07/16/2011 01:35 AM, Steven D'Aprano wrote:
> I have a custom object that customises the usual maths functions and
> operators, such as addition, multiplication, math.ceil etc.
>
> Is there a way to also customise math.sqrt? I don't think there is, but I
> may have missed something.
>
>
Create a file named myMath.py containing:
--------------------------------------
from math import *

def sqrt(x):
     ...whatever you want...
---------------------------------------

Then you can:
   import math #to get normal stuff and
   import myMath # to get your customized stuff
or
   import myMath as math # to get your stuff but named math.



Gary Herron



More information about the Python-list mailing list