The namespace for builtin functions?
From: Blair Hall (b.hall_at_irl.cri.nz)
Date: 11/30/03
- Next message: Jay O'Connor: "Re: The namespace for builtin functions?"
- Previous message: Jay O'Connor: "Re: sorting dictionary keys?"
- Next in thread: Jay O'Connor: "Re: The namespace for builtin functions?"
- Reply: Jay O'Connor: "Re: The namespace for builtin functions?"
- Reply: Peter Hansen: "Re: The namespace for builtin functions?"
- Reply: Fredrik Lundh: "Re: The namespace for builtin functions?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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.
- Next message: Jay O'Connor: "Re: The namespace for builtin functions?"
- Previous message: Jay O'Connor: "Re: sorting dictionary keys?"
- Next in thread: Jay O'Connor: "Re: The namespace for builtin functions?"
- Reply: Jay O'Connor: "Re: The namespace for builtin functions?"
- Reply: Peter Hansen: "Re: The namespace for builtin functions?"
- Reply: Fredrik Lundh: "Re: The namespace for builtin functions?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|