ec189b6c9fb65d6b7a62faf39934163d55e9e7b8
[profile/ivi/python.git] / Doc / library / __builtin__.rst
1
2 :mod:`__builtin__` --- Built-in objects
3 =======================================
4
5 .. module:: __builtin__
6    :synopsis: The module that provides the built-in namespace.
7
8
9 This module provides direct access to all 'built-in' identifiers of Python; for
10 example, ``__builtin__.open`` is the full name for the built-in function
11 :func:`open`.
12
13 This module is not normally accessed explicitly by most applications, but can be
14 useful in modules that provide objects with the same name as a built-in value,
15 but in which the built-in of that name is also needed.  For example, in a module
16 that wants to implement an :func:`open` function that wraps the built-in
17 :func:`open`, this module can be used directly::
18
19    import __builtin__
20
21    def open(path):
22        f = __builtin__.open(path, 'r')
23        return UpperCaser(f)
24
25    class UpperCaser:
26        '''Wrapper around a file that converts output to upper-case.'''
27
28        def __init__(self, f):
29            self._f = f
30
31        def read(self, count=-1):
32            return self._f.read(count).upper()
33
34        # ...
35
36 .. impl-detail::
37
38    Most modules have the name ``__builtins__`` (note the ``'s'``) made available
39    as part of their globals.  The value of ``__builtins__`` is normally either
40    this module or the value of this modules's :attr:`__dict__` attribute.  Since
41    this is an implementation detail, it may not be used by alternate
42    implementations of Python.