Re: Peculiar Behaviour of __builtins__

2011-05-12 Thread Gabriel Genellina
En Thu, 12 May 2011 22:59:24 -0300, Gabriel Genellina  
 escribió:


En Thu, 12 May 2011 20:29:57 -0300, Aman Nijhawan  
 escribió:



I was trying to call the builtin function min by using
getattr(__builtins__,'min')

This works at the interpretter prompt

However when I called it inside a module that was imported by another  
module

it fails and gives an attribute error


__builtins__ (note the final 's') is an implementation detail. You want  
the __builtin__ (no 's') module, renamed 'builtin' in Python 3.x


Should read "...renamed 'builtins' in Python 3.x, just to add to the  
confusion." :)



--
Gabriel Genellina

--
http://mail.python.org/mailman/listinfo/python-list


Re: Peculiar Behaviour of __builtins__

2011-05-12 Thread Gabriel Genellina
En Thu, 12 May 2011 20:29:57 -0300, Aman Nijhawan   
escribió:



I was trying to call the builtin function min by using
getattr(__builtins__,'min')

This works at the interpretter prompt

However when I called it inside a module that was imported by another  
module

it fails and gives an attribute error


__builtins__ (note the final 's') is an implementation detail. You want  
the __builtin__ (no 's') module, renamed 'builtin' in Python 3.x


py> import __builtin__
py> builtin_min = __builtin__.min
py> builtin_min([8,2,5])
2

See http://docs.python.org/library/__builtin__.html

Note: using getattr with a literal name is not so useful. Better to use  
dot notation.



--
Gabriel Genellina

--
http://mail.python.org/mailman/listinfo/python-list


Peculiar Behaviour of __builtins__

2011-05-12 Thread Aman Nijhawan
I was trying to call the builtin function min by using
getattr(__builtins__,'min')

This works at the interpretter prompt

However when I called it inside a module that was imported by another module
it fails and gives an attribute error

print getattr(__builtins__,'min')(range(20))
AttributeError: 'dict' object has no attribute 'min'

Also in the interpreter
>>>type(__builtins__)

but in my module

print type(__builtins__)


Can anyone help me understand whats going on here?


Thanks

-- 
Aman Nijhawan
-- 
http://mail.python.org/mailman/listinfo/python-list