473,388 Members | 1,198 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,388 software developers and data experts.

built-in function- module name clash

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
Jul 18 '05 #1
2 2676
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
Jul 18 '05 #2
Olivier Vierlinck <Ol***************@iba.be> 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.

Nope, it just uses the latest binding you requested for name 'abs',
whatever kind of object that may refer to, there's just one (at a given
time in a given scope).
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 ...)


A name at a given time in a scope can refer to ONE thing -- so either
'abs' names a function or it names a module, not both, in that one scope
at one and the same time.

You can import under a false name, no need to rename your abs.py:

import abs as myabs

or you can get an alias for the builtin before you trample on it:

builtin_abs = abs
import abs

and perhaps restore it later if you're done naming your abs module --
and other ways yet. But you just can't have barename 'abs' refer to two
different thing as the same name in the same scope.
Alex
Jul 18 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Alex Elbert | last post by:
Hi I have built dynamic HTMLTable. Now I want to attach it directly to the Email Body - it is already built, so why not to use a ready table. However, I cannot find the way of getting plain HTML...
0
by: Andrew Crook | last post by:
does MYSQL have a quota built into it! I need it limit the size of each database AndiC
1
by: Mark | last post by:
Is there a way to execute a statement that is built dynamically by a .NET application. For example I have a loop that is reading values from a database and I want to do something like the...
4
by: Yasutaka Ito | last post by:
Hi, Is there a way to determine which version of .NET Framework any given assembly is built with? thanks! -Yasutaka
1
by: William | last post by:
Looking for a pre built dotnet corporate or small business website template.
1
by: William | last post by:
Looking for a pre built dot net website for consulting business. I am trying to put up a quick business web for a dot net frame work. I have a provider already. I am trying to save time. Any...
1
by: Daniel | last post by:
is there any way to get to a unique build verion of an assembly at runtime? e.g. a version that is unique to the time that the assembly was built?
0
by: anthony Lichnewsky | last post by:
Hi, I have here a huge bunch of cygwin-built dlls using heavily posix api calls, and I wanted to know how to link them to some VC .NET library wrapper (using microsoft C runtime libraries this...
48
by: meyer | last post by:
Hi everyone, which compiler will Python 2.5 on Windows (Intel) be built with? I notice that Python 2.4 apparently has been built with the VS2003 toolkit compiler, and I read a post from Scott...
3
by: drewj840 | last post by:
I built a Windows service that sweeps a set of folders every 60 seconds and puts the files into a SQL Server database. I am creating a second service that will delete this set of folders and recreate...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.