The namespace for builtin functions?

From: Blair Hall (b.hall_at_irl.cri.nz)
Date: 11/30/03


Date: Sun, 30 Nov 2003 12:08:29 +1300

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.



Relevant Pages

  • Re: Where is Default Namespace located?
    ... confused myself though as I started a project and built quite a few pages ... > see that it does not set a default namespace. ... > Gery D. Dorazio ... > Development Engineer ...
    (microsoft.public.vsnet.ide)
  • Re: FSO
    ... there is a built in namespace just for ... filesystem access. ... It provides quite a bit of functionality to obtain information about ...
    (microsoft.public.dotnet.general)
  • Re: Using Windows API to FTP files in dot net
    ... If you're using .NET2, then FTP support is built into the System.Net ... namespace. ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: namespace import is slow
    ... built into [namespace import] is not performing well. ... If you have time to drop into the Tcl'ers chat sometime when I am there, ...
    (comp.lang.tcl)
  • Re: pretty print for built in types
    ... Is there a built in way to 'pretty print' a dict, list, and tuple ... (Amongst other types)? ... Dicts probably print the ugliest of them all, ...
    (comp.lang.python)