alternating the builtin functions

Jp Calderone exarkun at intarweb.us
Sun Oct 19 10:31:26 EDT 2003


On Sun, Oct 19, 2003 at 02:44:50PM +0200, Carlo v. Dango wrote:
> Hello there..
> 
> in the interactive shell in pythonWin I can type
> 
> >>>i= 2
> >>>__builtins__.isinstance(i, int)
> True
> 
> but when I make this function
> 
> def isinstance(object, classtype):
>     if __builtins__.isinstance(object, classtype):
>         return True
>     else:
>         if __builtins__.isinstance(object, Wrapper):       # if we are a 
> wrapper look somewhere else
>             return isinstance(object.ref, classtype)
>     return False
> 
> 
> it fails with the error
> 
> File "foo.py", line xxx, in isinstance
>     if __builtins__.isinstance(object, classtype):
> AttributeError: 'dict' object has no attribute 'isinstance'
> 
> 
> What am I doing wrong here?
> 

  Trying to put something in __builtins__.

  Doing this just creates behavior which is surprising to people who read
your program.  Just define your version in one of your modules and leave it
there.  When you need it, import it.

  Jp






More information about the Python-list mailing list