Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Re: Question about dir function

1 view
Skip to first unread message

Matt Nordhoff

unread,
Dec 19, 2009, 7:39:21 PM12/19/09
to Ray Holt, pytho...@python.org
Ray Holt wrote:
> When I run a dir(_builtins_) I get the error message that the name
> _builtins_ is not defined. I haven't tried the dir function on other
> functions, but can someone tell me why I am getting this message?
> Thanks, Ray

You are getting that message because the name "_builtins_" is not
defined, as it says. You were probably looking for "__builtins__", with
2 underscores on each end, not just 1.

BTW, "__builtins__" is a CPython implementation detail. If you want to
play with built-in objects, you should import the __builtin__ (no "s")
module and use that.
--
Matt Nordhoff

Tim Chase

unread,
Dec 19, 2009, 7:45:33 PM12/19/09
to python-list
Ray Holt wrote:
> When I run a dir(_builtins_) I get the error message that the name
> _builtins_ is not defined. I haven't tried the dir function on other
> functions, but can someone tell me why I am getting this message? Thanks,
> Ray
>
>
So close, and yet thrown by requisite extra underscores:

>>> dir(_builtins_) # one _ before and after
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name '_builtins_' is not defined
>>> dir(__builtins__) # two _'s before and after
['ArithmeticError', 'AssertionError', 'AttributeError',
'BaseException', 'DeprecationWarning', 'EOFError', 'Ellipsis',
'EnvironmentError', 'Exception', 'False',...]

-tkc


0 new messages