how to overload sqrt in a module?
Kent Johnson
kent at kentsjohnson.com
Sun Mar 5 13:03:45 CET 2006
Michael McNeil Forbes wrote:
> Is there anything really bad about the
> following? It works exactly as I would like, but I don't want to get in
> trouble down the road:
>
> module_f
> --------
> import math as my_math
>
> def set_math(custom_math):
> globals()['my_math'] = custom_math
This seems clearer to me:
def set_math(custom_math):
global my_math
my_math = custom_math
> Or, if one wants to use the "from __ import *" form:
>
> from math import *
>
> def set_math(custom_math):
> globals().update(custom_math.__dict__)
This will cause interesting trouble if custom_math doesn't implement all
the functions you use from math.
Kent
More information about the Python-list
mailing list