Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #5278 > unrolled thread

Re: Peculiar Behaviour of __builtins__

Started by"Gabriel Genellina" <gagsl-py2@yahoo.com.ar>
First post2011-05-12 22:59 -0300
Last post2011-05-12 22:59 -0300
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: Peculiar Behaviour of __builtins__ "Gabriel Genellina" <gagsl-py2@yahoo.com.ar> - 2011-05-12 22:59 -0300

#5278 — Re: Peculiar Behaviour of __builtins__

From"Gabriel Genellina" <gagsl-py2@yahoo.com.ar>
Date2011-05-12 22:59 -0300
SubjectRe: Peculiar Behaviour of __builtins__
Message-ID<mailman.1504.1305251910.9059.python-list@python.org>
En Thu, 12 May 2011 20:29:57 -0300, Aman Nijhawan <amannijhawan@gmail.com>  
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

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web