| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -64,9 +64,9 @@ def __getitem__(self, i): | |||
| 64 | 64 | ||
| 65 | 65 | ||
| 66 | 66 | def test(): | |
| 67 | - import time, __builtin__ | ||
| 67 | + import time, builtins | ||
| 68 | 68 | #Just a quick sanity check | |
| 69 | - correct_result = __builtin__.range(5, 100, 3) | ||
| 69 | + correct_result = builtins.range(5, 100, 3) | ||
| 70 | 70 | oldrange_result = list(oldrange(5, 100, 3)) | |
| 71 | 71 | genrange_result = list(genrange(5, 100, 3)) | |
| 72 | 72 | if genrange_result != correct_result or oldrange_result != correct_result: | |
@@ -81,7 +81,7 @@ def test(): | |||
| 81 | 81 | for i in genrange(1000): | |
| 82 | 82 | pass | |
| 83 | 83 | t3 = time.time() | |
| 84 | - for i in __builtin__.range(1000): | ||
| 84 | + for i in builtins.range(1000): | ||
| 85 | 85 | pass | |
| 86 | 86 | t4 = time.time() | |
| 87 | 87 | print(t2-t1, 'sec (old-style class)') | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -7,7 +7,7 @@ | |||
| 7 | 7 | ||
| 8 | 8 | """ | |
| 9 | 9 | ||
| 10 | - import sys, imp, __builtin__ | ||
| 10 | + import sys, imp, builtins | ||
| 11 | 11 | ||
| 12 | 12 | ||
| 13 | 13 | # Replacement for __import__() | |
@@ -117,7 +117,7 @@ def reload(module): | |||
| 117 | 117 | ||
| 118 | 118 | ||
| 119 | 119 | # Save the original hooks | |
| 120 | - original_import = __builtin__.__import__ | ||
| 120 | + original_import = builtins.__import__ | ||
| 121 | 121 | ||
| 122 | 122 | # Now install our hooks | |
| 123 | - __builtin__.__import__ = import_hook | ||
| 123 | + builtins.__import__ = import_hook | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -3,7 +3,7 @@ | |||
| 3 | 3 | import sys | |
| 4 | 4 | import socket | |
| 5 | 5 | import pickle | |
| 6 | - import __builtin__ | ||
| 6 | + import builtins | ||
| 7 | 7 | import os | |
| 8 | 8 | ||
| 9 | 9 | ||
@@ -90,8 +90,8 @@ def _recv(self, id): | |||
| 90 | 90 | if exception is None: | |
| 91 | 91 | return value | |
| 92 | 92 | x = exception | |
| 93 | - if hasattr(__builtin__, exception): | ||
| 94 | - x = getattr(__builtin__, exception) | ||
| 93 | + if hasattr(builtins, exception): | ||
| 94 | + x = getattr(builtins, exception) | ||
| 95 | 95 | elif exception in ('posix.error', 'mac.error'): | |
| 96 | 96 | x = os.error | |
| 97 | 97 | if x == exception: | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -17,7 +17,7 @@ Initialization, Finalization, and Threads | |||
| 17 | 17 | single: PyEval_AcquireLock() | |
| 18 | 18 | single: modules (in module sys) | |
| 19 | 19 | single: path (in module sys) | |
| 20 | - module: __builtin__ | ||
| 20 | + module: builtins | ||
| 21 | 21 | module: __main__ | |
| 22 | 22 | module: sys | |
| 23 | 23 | triple: module; search; path | |
@@ -29,7 +29,7 @@ Initialization, Finalization, and Threads | |||
| 29 | 29 | exception of :cfunc:`Py_SetProgramName`, :cfunc:`PyEval_InitThreads`, | |
| 30 | 30 | :cfunc:`PyEval_ReleaseLock`, and :cfunc:`PyEval_AcquireLock`. This initializes | |
| 31 | 31 | the table of loaded modules (``sys.modules``), and creates the fundamental | |
| 32 | - modules :mod:`__builtin__`, :mod:`__main__` and :mod:`sys`. It also initializes | ||
| 32 | + modules :mod:`builtins`, :mod:`__main__` and :mod:`sys`. It also initializes | ||
| 33 | 33 | the module search path (``sys.path``). It does not set ``sys.argv``; use | |
| 34 | 34 | :cfunc:`PySys_SetArgv` for that. This is a no-op when called for a second time | |
| 35 | 35 | (without calling :cfunc:`Py_Finalize` first). There is no return value; it is a | |
@@ -83,7 +83,7 @@ Initialization, Finalization, and Threads | |||
| 83 | 83 | .. cfunction:: PyThreadState* Py_NewInterpreter() | |
| 84 | 84 | ||
| 85 | 85 | .. index:: | |
| 86 | - module: __builtin__ | ||
| 86 | + module: builtins | ||
| 87 | 87 | module: __main__ | |
| 88 | 88 | module: sys | |
| 89 | 89 | single: stdout (in module sys) | |
@@ -93,7 +93,7 @@ Initialization, Finalization, and Threads | |||
| 93 | 93 | Create a new sub-interpreter. This is an (almost) totally separate environment | |
| 94 | 94 | for the execution of Python code. In particular, the new interpreter has | |
| 95 | 95 | separate, independent versions of all imported modules, including the | |
| 96 | - fundamental modules :mod:`__builtin__`, :mod:`__main__` and :mod:`sys`. The | ||
| 96 | + fundamental modules :mod:`builtins`, :mod:`__main__` and :mod:`sys`. The | ||
| 97 | 97 | table of loaded modules (``sys.modules``) and the module search path | |
| 98 | 98 | (``sys.path``) are also separate. The new environment has no ``sys.argv`` | |
| 99 | 99 | variable. It has new standard I/O stream file objects ``sys.stdin``, | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -507,7 +507,7 @@ interpreter can only be used after the interpreter has been initialized. | |||
| 507 | 507 | ||
| 508 | 508 | .. index:: | |
| 509 | 509 | single: Py_Initialize() | |
| 510 | - module: __builtin__ | ||
| 510 | + module: builtins | ||
| 511 | 511 | module: __main__ | |
| 512 | 512 | module: sys | |
| 513 | 513 | module: exceptions | |
@@ -516,7 +516,7 @@ interpreter can only be used after the interpreter has been initialized. | |||
| 516 | 516 | ||
| 517 | 517 | The basic initialization function is :cfunc:`Py_Initialize`. This initializes | |
| 518 | 518 | the table of loaded modules, and creates the fundamental modules | |
| 519 | - :mod:`__builtin__`, :mod:`__main__`, :mod:`sys`, and :mod:`exceptions`. It also | ||
| 519 | + :mod:`builtins`, :mod:`__main__`, :mod:`sys`, and :mod:`exceptions`. It also | ||
| 520 | 520 | initializes the module search path (``sys.path``). | |
| 521 | 521 | ||
| 522 | 522 | .. index:: single: PySys_SetArgv() | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -268,7 +268,7 @@ Glossary | |||
| 268 | 268 | dictionaries. There are the local, global and builtin namespaces as well | |
| 269 | 269 | as nested namespaces in objects (in methods). Namespaces support | |
| 270 | 270 | modularity by preventing naming conflicts. For instance, the functions | |
| 271 | - :func:`__builtin__.open` and :func:`os.open` are distinguished by their | ||
| 271 | + :func:`builtins.open` and :func:`os.open` are distinguished by their | ||
| 272 | 272 | namespaces. Namespaces also aid readability and maintainability by making | |
| 273 | 273 | it clear which module implements a function. For instance, writing | |
| 274 | 274 | :func:`random.seed` or :func:`itertools.izip` makes it clear that those | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,13 +1,13 @@ | |||
| 1 | 1 | ||
| 2 | - :mod:`__builtin__` --- Built-in objects | ||
| 3 | - ======================================= | ||
| 2 | + :mod:`builtins` --- Built-in objects | ||
| 3 | + ==================================== | ||
| 4 | 4 | ||
| 5 | - .. module:: __builtin__ | ||
| 5 | + .. module:: builtins | ||
| 6 | 6 | :synopsis: The module that provides the built-in namespace. | |
| 7 | 7 | ||
| 8 | 8 | ||
| 9 | 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 | ||
| 10 | + example, ``builtins.open`` is the full name for the built-in function | ||
| 11 | 11 | :func:`open`. See chapter :ref:`builtin`. | |
| 12 | 12 | ||
| 13 | 13 | This module is not normally accessed explicitly by most applications, but can be | |
@@ -16,10 +16,10 @@ but in which the built-in of that name is also needed. For example, in a module | |||
| 16 | 16 | that wants to implement an :func:`open` function that wraps the built-in | |
| 17 | 17 | :func:`open`, this module can be used directly:: | |
| 18 | 18 | ||
| 19 | - import __builtin__ | ||
| 19 | + import builtins | ||
| 20 | 20 | ||
| 21 | 21 | def open(path): | |
| 22 | - f = __builtin__.open(path, 'r') | ||
| 22 | + f = builtins.open(path, 'r') | ||
| 23 | 23 | return UpperCaser(f) | |
| 24 | 24 | ||
| 25 | 25 | class UpperCaser: | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -356,7 +356,7 @@ available. They are listed here in alphabetical order. | |||
| 356 | 356 | dictionaries as global and local namespace. If the *globals* dictionary is | |
| 357 | 357 | present and lacks '__builtins__', the current globals are copied into *globals* | |
| 358 | 358 | before *expression* is parsed. This means that *expression* normally has full | |
| 359 | - access to the standard :mod:`__builtin__` module and restricted environments are | ||
| 359 | + access to the standard :mod:`builtins` module and restricted environments are | ||
| 360 | 360 | propagated. If the *locals* dictionary is omitted it defaults to the *globals* | |
| 361 | 361 | dictionary. If both dictionaries are omitted, the expression is executed in the | |
| 362 | 362 | environment where :keyword:`eval` is called. The return value is the result of | |
@@ -398,7 +398,7 @@ available. They are listed here in alphabetical order. | |||
| 398 | 398 | ||
| 399 | 399 | If the *globals* dictionary does not contain a value for the key | |
| 400 | 400 | ``__builtins__``, a reference to the dictionary of the built-in module | |
| 401 | - :mod:`__builtin__` is inserted under that key. That way you can control what | ||
| 401 | + :mod:`builtins` is inserted under that key. That way you can control what | ||
| 402 | 402 | builtins are available to the executed code by inserting your own | |
| 403 | 403 | ``__builtins__`` dictionary into *globals* before passing it to :func:`exec`. | |
| 404 | 404 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -108,7 +108,7 @@ This code is intended to be read, not executed. However, it does work | |||
| 108 | 108 | ||
| 109 | 109 | :: | |
| 110 | 110 | ||
| 111 | - import sys, imp, __builtin__ | ||
| 111 | + import sys, imp, builtins | ||
| 112 | 112 | ||
| 113 | 113 | # Replacement for __import__() | |
| 114 | 114 | def import_hook(name, globals=None, locals=None, fromlist=None): | |
@@ -218,12 +218,12 @@ This code is intended to be read, not executed. However, it does work | |||
| 218 | 218 | ||
| 219 | 219 | ||
| 220 | 220 | # Save the original hooks | |
| 221 | - original_import = __builtin__.__import__ | ||
| 222 | - original_reload = __builtin__.reload | ||
| 221 | + original_import = builtins.__import__ | ||
| 222 | + original_reload = builtins.reload | ||
| 223 | 223 | ||
| 224 | 224 | # Now install our hooks | |
| 225 | - __builtin__.__import__ = import_hook | ||
| 226 | - __builtin__.reload = reload_hook | ||
| 225 | + builtins.__import__ = import_hook | ||
| 226 | + builtins.reload = reload_hook | ||
| 227 | 227 | ||
| 228 | 228 | .. index:: | |
| 229 | 229 | module: knee | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -13,7 +13,7 @@ overview: | |||
| 13 | 13 | .. toctree:: | |
| 14 | 14 | ||
| 15 | 15 | sys.rst | |
| 16 | - __builtin__.rst | ||
| 16 | + builtins.rst | ||
| 17 | 17 | __main__.rst | |
| 18 | 18 | warnings.rst | |
| 19 | 19 | contextlib.rst | |
| Back | FazBrowse Home | New Git URL |
0 commit comments