summaryrefslogtreecommitdiff
path: root/devdocs/python~3.12/library%2Fbuiltins.html
blob: 779799b3b2c130e8307d7c7131cba64d29937524 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
 <span id="builtins-built-in-objects"></span><h1>builtins — Built-in objects</h1>  <p>This module provides direct access to all ‘built-in’ identifiers of Python; for example, <code>builtins.open</code> is the full name for the built-in function <a class="reference internal" href="functions#open" title="open"><code>open()</code></a>. See <a class="reference internal" href="functions#built-in-funcs"><span class="std std-ref">Built-in Functions</span></a> and <a class="reference internal" href="constants#built-in-consts"><span class="std std-ref">Built-in Constants</span></a> for documentation.</p> <p>This module is not normally accessed explicitly by most applications, but can be useful in modules that provide objects with the same name as a built-in value, but in which the built-in of that name is also needed. For example, in a module that wants to implement an <a class="reference internal" href="functions#open" title="open"><code>open()</code></a> function that wraps the built-in <a class="reference internal" href="functions#open" title="open"><code>open()</code></a>, this module can be used directly:</p> <pre data-language="python">import builtins

def open(path):
    f = builtins.open(path, 'r')
    return UpperCaser(f)

class UpperCaser:
    '''Wrapper around a file that converts output to uppercase.'''

    def __init__(self, f):
        self._f = f

    def read(self, count=-1):
        return self._f.read(count).upper()

    # ...
</pre> <p>As an implementation detail, most modules have the name <code>__builtins__</code> made available as part of their globals. The value of <code>__builtins__</code> is normally either this module or the value of this module’s <a class="reference internal" href="stdtypes#object.__dict__" title="object.__dict__"><code>__dict__</code></a> attribute. Since this is an implementation detail, it may not be used by alternate implementations of Python.</p> <div class="_attribution">
  <p class="_attribution-p">
    &copy; 2001&ndash;2023 Python Software Foundation<br>Licensed under the PSF License.<br>
    <a href="https://docs.python.org/3.12/library/builtins.html" class="_attribution-link">https://docs.python.org/3.12/library/builtins.html</a>
  </p>
</div>