473,387 Members | 1,512 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

__builtins__

Hi there,
I'm a newby in python (I know a little in programmation) and I have
a lot of questions on builtins but my first one is about modules...

I have seen that if I type help() at a prompt, and then 'modules',
I'll be given a list of all modules available, thanks to this group..
But I have seen the differences between them and the one in
dir(__builtins__).
Why are some modules in __builtins__ and others don't ? (UserDict for
example)
Why dir(__builtins__) gives me "math" but not help(__builtins__) ?

What are the differences between __builtins__ and __builtin__ ? (By
the way, I have python 2.4)

Finally, if I do del(__builtins__), what can I do to repair the
"mistake" (as I got an import error __import__ not found if I want to
import __builtins__...?

That's may be obvious for you, but that's all strange to me and I
didn't find answers on the net...
Feb 8 '08 #1
3 4150
On Fri, 08 Feb 2008 00:25:14 -0800, loquehumaine wrote:
I have seen that if I type help() at a prompt, and then 'modules',
I'll be given a list of all modules available, thanks to this group..
But I have seen the differences between them and the one in
dir(__builtins__).
Why are some modules in __builtins__ and others don't ? (UserDict for
example)
`__builtins__` doesn't contain modules::

Python 2.4.4 (#2, Apr 12 2007, 21:03:11)
[GCC 4.1.2 (Ubuntu 4.1.2-0ubuntu4)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>import inspect
inspect.getmembers(__builtins__, inspect.ismodule)
[]
Why dir(__builtins__) gives me "math" but not help(__builtins__) ?
So there's no 'math' in `__builtins__`::
>>'math' in dir(__builtins__)
False
What are the differences between __builtins__ and __builtin__ ? (By
the way, I have python 2.4)
`__builtins__` is an implementation detail, and `__builtin__` is a name
of a module you can import. You should not use `__builtins__` but import
`__builtin__` and inspect that instead of `__builtins__`.

The (symmetric) difference of the two is empty::
>>import __builtin__
set(dir(__builtins__)).symmetric_difference(dir( __builtin__))
set([])
Finally, if I do del(__builtins__), what can I do to repair the
"mistake" (as I got an import error __import__ not found if I want to
import __builtins__...?
Don't ``del __builtins__`` in the first place. :-)
That's may be obvious for you, but that's all strange to me and I
didn't find answers on the net...
So the real question is, why you see 'math' in `__builtins__`. It should
not be there.

Ciao,
Marc 'BlackJack' Rintsch
Feb 8 '08 #2
LHB
Marc 'BlackJack' Rintsch a écrit :
On Fri, 08 Feb 2008 00:25:14 -0800, loquehumaine wrote:
>I have seen that if I type help() at a prompt, and then 'modules',
I'll be given a list of all modules available, thanks to this group..
But I have seen the differences between them and the one in
dir(__builtins__).
Why are some modules in __builtins__ and others don't ? (UserDict for
example)

`__builtins__` doesn't contain modules::
You are right... I don't know why I thought there was math here... It's
not in sys.modules either...
Is there "a place" where you can find a list of 'some' available modules
('standard' ones like math, sys, ...) but not all, or I really need a
break during the week-end?
If so, what the difference between the 'present' and the 'missing' ones?

For example, in http://docs.python.org/modindex.html for math: "This
module is always available." unlike pickle or HTMLParser. Is this only
because of the versions of Python?

I think I have mixed-up a lot of things and that I need a little bit
more of readings about builtin things... (Doc that goes further than
http://docs.python.org/lib/builtin.html)
Python 2.4.4 (#2, Apr 12 2007, 21:03:11)
[GCC 4.1.2 (Ubuntu 4.1.2-0ubuntu4)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>import inspect
>>inspect.getmembers(__builtins__, inspect.ismodule)
[]
At least I have learn a new module =)

`__builtins__` is an implementation detail, and `__builtin__` is a name
of a module you can import. You should not use `__builtins__` but import
`__builtin__` and inspect that instead of `__builtins__`.
Ok. Should I only see `__builtins__` as an access to builtin
functions/exception/... ?
Don't ``del __builtins__`` in the first place. :-)
Fair enough ^_^
So the real question is, why you see 'math' in `__builtins__`. It should
not be there.
I think the answer is that I need more rest...
>
Ciao,
Marc 'BlackJack' Rintsch
Thanks a lot,

LHB
Feb 8 '08 #3
LHB <lo**********@gmail.comwrites:
Marc 'BlackJack' Rintsch a écrit :
`__builtins__` is an implementation detail, and `__builtin__` is a name
of a module you can import. You should not use `__builtins__` but import
`__builtin__` and inspect that instead of `__builtins__`.
Ok. Should I only see `__builtins__` as an access to builtin
functions/exception/... ?
No, if you want that access, explicitly 'import __builtin__' and
access them that way. Ignore '__builtins__' altogether as an
implementation detail. (This is difficult to adhere to because the
names are confusingly similar; this is an acknowledged wart in current
Python.)

IIRC this behaviour will change in Python 3.0, where 'import
__builtin__' will be the *only* way to get at builtins from normal
code. At least, I'm now writing my code as though that's the case :-)

--
\ “The man who is denied the opportunity of taking decisions of |
`\ importance begins to regard as important the decisions he is |
_o__) allowed to take.†—C. Northcote Parkinson |
Ben Finney
Feb 9 '08 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Opinder | last post by:
Hi, For the Python experts out there: Are there any side effects in assigning new variables to the __builtins__ module for the purpose of exposing variables to imported modules. For...
0
by: Mathieu Fenniak | last post by:
Good day, I'm writing an application which creates modules and runs Python code on the fly, embedding Python. The main function of the code is loaded into the __main__ module: (Error checking...
1
by: Matteo Merli | last post by:
Hi, is there a way to save objects in the __builtins__ namespace? the goal is to make them available in all the modules of my app, without reimporting all the things and keep references... The...
1
by: Michael Hohn | last post by:
Hi, using the file builtin_check.py with content # Module builtin_check # Inconstency in the binding of __builtins__ def get_binding(name): return locals() def get_global_binding(name):
4
by: Collin Winter | last post by:
Hallo all, As it currently stands, the type of the global __builtins__ differs depending on whether you're in the __main__ namespace (__builtins__ is a module) or not (its a dict). I was...
1
by: Adam Hupp | last post by:
I've noticed some unexpected behavior with __builtins__ during module import. It seems that during module import __builtins__ is a dict but at all other times it is a module. For example, if...
0
by: Patrick Maupin | last post by:
__builtins__ in 2.5.2 doesn't seem to behave like I remember it did the last time I did some custom stuff with it, a very long time ago. This isn't surprising, because of ongoing optimization,...
3
by: Gabriel Genellina | last post by:
En Sun, 07 Sep 2008 14:00:48 -0300, Patrick Maupin <pmaupin@gmail.comescribió: Python takes some shortcuts when dealing with builtins. I'll just describe what happens (I won't say whether it is...
0
by: Lie Ryan | last post by:
On Tue, 30 Sep 2008 16:04:34 -0500, William Purcell wrote: when you pass mydict, it is used as the global variables in the eval, right? Then, you passed a code to eval('...', mydict), sometimes...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.