The namespace for builtin functions?

Blair Hall b.hall at irl.cri.nz
Sat Nov 29 18:08:29 EST 2003


Can anyone please tell me how to correctly use a built in function
when there is a function of the same name in local scope?

Here is an example. Suppose the following is in myApply.py:

def apply(func,seq):
     #
     # Code can default to
     # built-in definition in some cases:
     return __builtins__.apply(func,seq)

#-------------------------------------
if(__name__ == '__main__'):

     print "Three = ",apply(lambda x,y: x+y, (1,2) )


This seems to work, but if I import the definition of 'apply', like:

 >>> from myApply import apply
 >>> apply(lambda x,y: x+y, (1,2) )

I get a crash:

Traceback (most recent call last):
   File "<interactive input>", line 1, in ?
   File "C:\proj_py\Learning\builtins\myApply.py", line 5, in apply
     return __builtins__.apply(func,seq)
AttributeError: 'dict' object has no attribute 'apply'

I can't see what to use instead of '__builtins__' as the
namespace for the built in functions.





More information about the Python-list mailing list