built-in function- module name clash

Jason Lai jmlai at uci.edu
Mon Sep 6 06:08:07 EDT 2004


Olivier Vierlinck wrote:
> Hi,
> 
> I've a python script using somecalls to the abs() built-in function.
> 
> Now, I have to import a module named 'abs' too...
> The consequence if that line code like
> 
> 	  if (abs(a-b) < epsilon:
> 		...
> does not work anymore, with this error msg:
> 
> 	TypeError: 'module' object is not callable
> 
> Clearly, the interpreter tries first to consider 'abs' as a module name rather than a built-in function name.
> Any idea on how to force it to call the abs() fct? Some kind of scoping or specific syntax?
> (I could rename the abs module too but ...)
> 
> Thanks for your help,
> cheers,
> Olivier

__builtins__.abs(a-b)

Not very pretty, but it works.

- Jason



More information about the Python-list mailing list