chunk_id stringlengths 36 36 | source stringclasses 35
values | source_url stringlengths 0 290 | upstream_license stringclasses 1
value | document_id stringlengths 36 36 | chunk_index int64 0 324k | retrieved_at stringclasses 2
values | chunker_version stringclasses 4
values | content_hash stringlengths 15 64 | content stringlengths 50 44.7k | namespace stringclasses 9
values | source_name stringclasses 35
values | raw_text stringlengths 50 44.7k | cleaned_text stringlengths 50 44.7k | tags stringclasses 49
values | collection_name stringclasses 11
values |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
7600bc7a-33a5-4e67-a7d5-2b3c2d6edf4a | CPython Docs | file://datasets/cpython/Doc/faq/programming.rst | unknown | edda7b58-bd69-4060-9295-d9036b4690eb | 1,679 | supabase-export-v2 | d8adf106a95ca61d | Note that using a module is also the basis for implementing the singleton design pattern, for the same reason.
What are the "best practices" for using import in a module? ----------------------------------------------------------- | trusted_official_docs | CPython Docs | Note that using a module is also the basis for implementing the singleton design pattern, for the same reason.
What are the "best practices" for using import in a module? ----------------------------------------------------------- | Note that using a module is also the basis for implementing the singleton design pattern, for the same reason.
What are the "best practices" for using import in a module? ----------------------------------------------------------- | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
77550930-89d3-4345-979a-5eb4e30467ef | CPython Docs | file://datasets/cpython/Doc/faq/programming.rst | unknown | edda7b58-bd69-4060-9295-d9036b4690eb | 2,142 | supabase-export-v2 | 0f748e73a2e984eb | exports (globals, functions, and classes that don't need imported base classes) * ``import`` statements * active code (including globals that are initialized from imported values).
Van Rossum doesn't like this approach much because the imports appear in a
strange place, but it does work. | trusted_official_docs | CPython Docs | exports (globals, functions, and classes that don't need imported base classes) * ``import`` statements * active code (including globals that are initialized from imported values).
Van Rossum doesn't like this approach much because the imports appear in a
strange place, but it does work. | exports (globals, functions, and classes that don't need imported base classes) * ``import`` statements * active code (including globals that are initialized from imported values).
Van Rossum doesn't like this approach much because the imports appear in a
strange place, but it does work. | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
77c2bcee-7bc3-4584-b78f-8044ce8ac500 | CPython Docs | file://datasets/cpython/Doc/faq/programming.rst | unknown | edda7b58-bd69-4060-9295-d9036b4690eb | 1,974 | supabase-export-v2 | b4ad18ef6790e450 | What is self? -------------
Self is merely a conventional name for the first argument of a method. A method
defined as ``meth(self, a, b, c)`` should be called as ``x.meth(a, b, c)`` for
some instance ``x`` of the class in which the definition occurs; the called
method will think it is called as ``meth(x, a, b, c)``. | trusted_official_docs | CPython Docs | What is self? -------------
Self is merely a conventional name for the first argument of a method. A method
defined as ``meth(self, a, b, c)`` should be called as ``x.meth(a, b, c)`` for
some instance ``x`` of the class in which the definition occurs; the called
method will think it is called as ``meth(x, a, b, c)``. | What is self? -------------
Self is merely a conventional name for the first argument of a method. A method
defined as ``meth(self, a, b, c)`` should be called as ``x.meth(a, b, c)`` for
some instance ``x`` of the class in which the definition occurs; the called
method will think it is called as ``meth(x, a, b, c)``. | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
781bc648-774a-43b0-a957-6f55069f32c5 | CPython Docs | file://datasets/cpython/Doc/faq/programming.rst | unknown | edda7b58-bd69-4060-9295-d9036b4690eb | 1,722 | supabase-export-v2 | e56a092875210901 | x >>> x = x + 1 # 5 can't be mutated, we are creating a new object here >>> x 6 >>> y 5
we can see that in this case ``x`` and ``y`` are not equal anymore. This is
because integers are :term:`immutable`, and when we do ``x = x + 1`` we are not
mutating the int ``5`` by incrementing its value; instead, we are creating a... | trusted_official_docs | CPython Docs | x >>> x = x + 1 # 5 can't be mutated, we are creating a new object here >>> x 6 >>> y 5
we can see that in this case ``x`` and ``y`` are not equal anymore. This is
because integers are :term:`immutable`, and when we do ``x = x + 1`` we are not
mutating the int ``5`` by incrementing its value; instead, we are creating a... | x >>> x = x + 1 # 5 can't be mutated, we are creating a new object here >>> x 6 >>> y 5
we can see that in this case ``x`` and ``y`` are not equal anymore. This is
because integers are :term:`immutable`, and when we do ``x = x + 1`` we are not
mutating the int ``5`` by incrementing its value; instead, we are creating a... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
783b90dc-0b5b-40b0-b1cd-fd8a7e289a81 | CPython Docs | file://datasets/cpython/Doc/faq/programming.rst | unknown | edda7b58-bd69-4060-9295-d9036b4690eb | 1,680 | supabase-export-v2 | 0fea4f53854a15c2 | What are the "best practices" for using import in a module? -----------------------------------------------------------
In general, don't use ``from modulename import *``. Doing so clutters the
importer's namespace, and makes it much harder for linters to detect undefined
names. | trusted_official_docs | CPython Docs | What are the "best practices" for using import in a module? -----------------------------------------------------------
In general, don't use ``from modulename import *``. Doing so clutters the
importer's namespace, and makes it much harder for linters to detect undefined
names. | What are the "best practices" for using import in a module? -----------------------------------------------------------
In general, don't use ``from modulename import *``. Doing so clutters the
importer's namespace, and makes it much harder for linters to detect undefined
names. | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
79bc7277-63f4-4e85-8696-70f8912a0ec6 | CPython Docs | file://datasets/cpython/Doc/faq/programming.rst | unknown | edda7b58-bd69-4060-9295-d9036b4690eb | 1,931 | supabase-export-v2 | ed8bdc31de0d602a | w, h = 2, 3 A = [[None] * w for i in range(h)]
Or, you can use an extension that provides a matrix datatype; `NumPy
<https://numpy.org/>`_ is the best known. | trusted_official_docs | CPython Docs | w, h = 2, 3 A = [[None] * w for i in range(h)]
Or, you can use an extension that provides a matrix datatype; `NumPy
<https://numpy.org/>`_ is the best known. | w, h = 2, 3 A = [[None] * w for i in range(h)]
Or, you can use an extension that provides a matrix datatype; `NumPy
<https://numpy.org/>`_ is the best known. | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
7ba0b4ba-06ec-4fc0-934e-30beafa2fd92 | CPython Docs | file://datasets/cpython/Doc/faq/programming.rst | unknown | edda7b58-bd69-4060-9295-d9036b4690eb | 1,982 | supabase-export-v2 | 9640e73634fffc1f | >>> c = C() >>> isinstance(c, C) # direct True >>> isinstance(c, P) # indirect True >>> isinstance(c, Mapping) # virtual True
# Actual inheritance chain
>>> type(c).__mro__
(<class 'C'>, <class 'P'>, <class 'object'>) | trusted_official_docs | CPython Docs | >>> c = C() >>> isinstance(c, C) # direct True >>> isinstance(c, P) # indirect True >>> isinstance(c, Mapping) # virtual True
# Actual inheritance chain
>>> type(c).__mro__
(<class 'C'>, <class 'P'>, <class 'object'>) | >>> c = C() >>> isinstance(c, C) # direct True >>> isinstance(c, P) # indirect True >>> isinstance(c, Mapping) # virtual True
# Actual inheritance chain
>>> type(c).__mro__
(<class 'C'>, <class 'P'>, <class 'object'>) | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
7be7a3ce-1bf8-4d17-8fe0-0b07d4868716 | CPython Docs | file://datasets/cpython/Doc/faq/programming.rst | unknown | edda7b58-bd69-4060-9295-d9036b4690eb | 1,769 | supabase-export-v2 | 20d961f01bd894ff | ... >>> B = A >>> a = B() >>> b = a >>> print(b) <__main__.A object at 0x16D07CC> >>> print(a) <__main__.A object at 0x16D07CC>
Arguably the class has a name: even though it is bound to two names and invoked
through the name ``B`` the created instance is still reported as an instance of
class ``A``. However, it is impo... | trusted_official_docs | CPython Docs | ... >>> B = A >>> a = B() >>> b = a >>> print(b) <__main__.A object at 0x16D07CC> >>> print(a) <__main__.A object at 0x16D07CC>
Arguably the class has a name: even though it is bound to two names and invoked
through the name ``B`` the created instance is still reported as an instance of
class ``A``. However, it is impo... | ... >>> B = A >>> a = B() >>> b = a >>> print(b) <__main__.A object at 0x16D07CC> >>> print(a) <__main__.A object at 0x16D07CC>
Arguably the class has a name: even though it is bound to two names and invoked
through the name ``B`` the created instance is still reported as an instance of
class ``A``. However, it is impo... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
7ce6208b-4c87-46a5-a148-d44de2a1bb5c | CPython Docs | file://datasets/cpython/Doc/faq/programming.rst | unknown | edda7b58-bd69-4060-9295-d9036b4690eb | 1,805 | supabase-export-v2 | 5e275885fbbf6f44 | >>> a = 0o10 >>> a 8
Hexadecimal is just as easy. Simply precede the hexadecimal number with a zero,
and then a lower or uppercase "x". Hexadecimal digits can be specified in lower
or uppercase. For example, in the Python interpreter:: | trusted_official_docs | CPython Docs | >>> a = 0o10 >>> a 8
Hexadecimal is just as easy. Simply precede the hexadecimal number with a zero,
and then a lower or uppercase "x". Hexadecimal digits can be specified in lower
or uppercase. For example, in the Python interpreter:: | >>> a = 0o10 >>> a 8
Hexadecimal is just as easy. Simply precede the hexadecimal number with a zero,
and then a lower or uppercase "x". Hexadecimal digits can be specified in lower
or uppercase. For example, in the Python interpreter:: | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
7d260f1d-0f1f-4a10-b6c5-f6a9f52c4e77 | CPython Docs | file://datasets/cpython/Doc/faq/programming.rst | unknown | edda7b58-bd69-4060-9295-d9036b4690eb | 1,780 | supabase-export-v2 | 9cde72e708aaa660 | The same is true of the various assignment operators (``=``, ``+=``, and so on). They are not truly operators but syntactic delimiters in assignment statements.
Is there an equivalent of C's "?:" ternary operator? ---------------------------------------------------- | trusted_official_docs | CPython Docs | The same is true of the various assignment operators (``=``, ``+=``, and so on). They are not truly operators but syntactic delimiters in assignment statements.
Is there an equivalent of C's "?:" ternary operator? ---------------------------------------------------- | The same is true of the various assignment operators (``=``, ``+=``, and so on). They are not truly operators but syntactic delimiters in assignment statements.
Is there an equivalent of C's "?:" ternary operator? ---------------------------------------------------- | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
8164e0b9-251f-4d18-acd1-0b71fd01e6ad | CPython Docs | file://datasets/cpython/Doc/faq/programming.rst | unknown | edda7b58-bd69-4060-9295-d9036b4690eb | 1,788 | supabase-export-v2 | ea1bdf1daa058d72 | Is it possible to write obfuscated one-liners in Python? --------------------------------------------------------
Yes. Usually this is done by nesting :keyword:`lambda` within
:keyword:`!lambda`. See the following three examples, slightly adapted from Ulf Bartelt:: | trusted_official_docs | CPython Docs | Is it possible to write obfuscated one-liners in Python? --------------------------------------------------------
Yes. Usually this is done by nesting :keyword:`lambda` within
:keyword:`!lambda`. See the following three examples, slightly adapted from Ulf Bartelt:: | Is it possible to write obfuscated one-liners in Python? --------------------------------------------------------
Yes. Usually this is done by nesting :keyword:`lambda` within
:keyword:`!lambda`. See the following three examples, slightly adapted from Ulf Bartelt:: | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
82677d21-8818-4d21-86b1-0d476c4989bc | CPython Docs | file://datasets/cpython/Doc/faq/programming.rst | unknown | edda7b58-bd69-4060-9295-d9036b4690eb | 2,150 | supabase-export-v2 | b5616b405e23b432 | one imports the same basic module, the basic module would be parsed and re-parsed many times. To force re-reading of a changed module, do this::
import importlib
import modname
importlib.reload(modname) | trusted_official_docs | CPython Docs | one imports the same basic module, the basic module would be parsed and re-parsed many times. To force re-reading of a changed module, do this::
import importlib
import modname
importlib.reload(modname) | one imports the same basic module, the basic module would be parsed and re-parsed many times. To force re-reading of a changed module, do this::
import importlib
import modname
importlib.reload(modname) | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
83015cd7-5f35-4483-8a60-088a33752a1b | CPython Docs | file://datasets/cpython/Doc/faq/programming.rst | unknown | edda7b58-bd69-4060-9295-d9036b4690eb | 2,049 | supabase-export-v2 | d083afeeae4e0d37 | call :meth:`!__del__` directly -- :meth:`!__del__` should call ``close()`` and ``close()`` should make sure that it can be called more than once for the same object.
Another way to avoid cyclical references is to use the :mod:`weakref` module,
which allows you to point to objects without incrementing their reference co... | trusted_official_docs | CPython Docs | call :meth:`!__del__` directly -- :meth:`!__del__` should call ``close()`` and ``close()`` should make sure that it can be called more than once for the same object.
Another way to avoid cyclical references is to use the :mod:`weakref` module,
which allows you to point to objects without incrementing their reference co... | call :meth:`!__del__` directly -- :meth:`!__del__` should call ``close()`` and ``close()`` should make sure that it can be called more than once for the same object.
Another way to avoid cyclical references is to use the :mod:`weakref` module,
which allows you to point to objects without incrementing their reference co... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
83b1dbd4-ba08-424c-8fe5-f5ef8ba6f306 | CPython Docs | file://datasets/cpython/Doc/faq/programming.rst | unknown | edda7b58-bd69-4060-9295-d9036b4690eb | 2,101 | supabase-export-v2 | e54fc827740cdab4 | def __init__(self, station_id): self._station_id = station_id # The _station_id is private and immutable
def current_temperature(self):
"Latest hourly observation"
# Do not cache this because old results
# can be out of date. | trusted_official_docs | CPython Docs | def __init__(self, station_id): self._station_id = station_id # The _station_id is private and immutable
def current_temperature(self):
"Latest hourly observation"
# Do not cache this because old results
# can be out of date. | def __init__(self, station_id): self._station_id = station_id # The _station_id is private and immutable
def current_temperature(self):
"Latest hourly observation"
# Do not cache this because old results
# can be out of date. | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
83ed37fb-8bf8-4449-90bb-9035c6f4ece8 | CPython Docs | file://datasets/cpython/Doc/faq/programming.rst | unknown | edda7b58-bd69-4060-9295-d9036b4690eb | 1,637 | supabase-export-v2 | 2a3801d32f274529 | The following packages can help with the creation of console and GUI executables:
* `Nuitka <https://nuitka.net/>`_ (Cross-platform)
* `PyInstaller <https://pyinstaller.org/>`_ (Cross-platform)
* `PyOxidizer <https://pyoxidizer.readthedocs.io/en/stable/>`_ (Cross-platform)
* `cx_Freeze <https://marcelotduarte.github.io... | trusted_official_docs | CPython Docs | The following packages can help with the creation of console and GUI executables:
* `Nuitka <https://nuitka.net/>`_ (Cross-platform)
* `PyInstaller <https://pyinstaller.org/>`_ (Cross-platform)
* `PyOxidizer <https://pyoxidizer.readthedocs.io/en/stable/>`_ (Cross-platform)
* `cx_Freeze <https://marcelotduarte.github.io... | The following packages can help with the creation of console and GUI executables:
* `Nuitka <https://nuitka.net/>`_ (Cross-platform)
* `PyInstaller <https://pyinstaller.org/>`_ (Cross-platform)
* `PyOxidizer <https://pyoxidizer.readthedocs.io/en/stable/>`_ (Cross-platform)
* `cx_Freeze <https://marcelotduarte.github.io... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
85b441ae-5d93-4a8a-ac9c-ea9281939356 | CPython Docs | file://datasets/cpython/Doc/faq/programming.rst | unknown | edda7b58-bd69-4060-9295-d9036b4690eb | 1,826 | supabase-export-v2 | 6d3d885fc20843b4 | it from. However, if you need an object with the ability to modify in-place Unicode data, try using an :class:`io.StringIO` object or the :mod:`array` module::
>>> import io
>>> s = "Hello, world"
>>> sio = io.StringIO(s)
>>> sio.getvalue()
'Hello, world'
>>> sio.seek(7)
7
>>> sio.write("there!")
6
>>> sio.get... | trusted_official_docs | CPython Docs | it from. However, if you need an object with the ability to modify in-place Unicode data, try using an :class:`io.StringIO` object or the :mod:`array` module::
>>> import io
>>> s = "Hello, world"
>>> sio = io.StringIO(s)
>>> sio.getvalue()
'Hello, world'
>>> sio.seek(7)
7
>>> sio.write("there!")
6
>>> sio.get... | it from. However, if you need an object with the ability to modify in-place Unicode data, try using an :class:`io.StringIO` object or the :mod:`array` module::
>>> import io
>>> s = "Hello, world"
>>> sio = io.StringIO(s)
>>> sio.getvalue()
'Hello, world'
>>> sio.seek(7)
7
>>> sio.write("there!")
6
>>> sio.get... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
8664eda7-9476-4d25-8d35-d946ce604098 | CPython Docs | file://datasets/cpython/Doc/faq/programming.rst | unknown | edda7b58-bd69-4060-9295-d9036b4690eb | 2,103 | supabase-export-v2 | 5bd83e884182b3d7 | @cached_property def location(self): "Return the longitude/latitude coordinates of the station" # Result only depends on the station_id
@lru_cache(maxsize=20)
def historic_rainfall(self, date, units='mm'):
"Rainfall on a given date"
# Depends on the station_id, date, and units. | trusted_official_docs | CPython Docs | @cached_property def location(self): "Return the longitude/latitude coordinates of the station" # Result only depends on the station_id
@lru_cache(maxsize=20)
def historic_rainfall(self, date, units='mm'):
"Rainfall on a given date"
# Depends on the station_id, date, and units. | @cached_property def location(self): "Return the longitude/latitude coordinates of the station" # Result only depends on the station_id
@lru_cache(maxsize=20)
def historic_rainfall(self, date, units='mm'):
"Rainfall on a given date"
# Depends on the station_id, date, and units. | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
8757ee33-d2a1-4e3d-b8c0-fec5ff63162e | CPython Docs | file://datasets/cpython/Doc/faq/programming.rst | unknown | edda7b58-bd69-4060-9295-d9036b4690eb | 2,008 | supabase-export-v2 | 46ec4d2e3e4ac9c7 | How can I organize my code to make it easier to change the base class? ----------------------------------------------------------------------
You could assign the base class to an alias and derive from the alias. Then all
you have to change is the value assigned to the alias. Incidentally, this trick
is also handy if y... | trusted_official_docs | CPython Docs | How can I organize my code to make it easier to change the base class? ----------------------------------------------------------------------
You could assign the base class to an alias and derive from the alias. Then all
you have to change is the value assigned to the alias. Incidentally, this trick
is also handy if y... | How can I organize my code to make it easier to change the base class? ----------------------------------------------------------------------
You could assign the base class to an alias and derive from the alias. Then all
you have to change is the value assigned to the alias. Incidentally, this trick
is also handy if y... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
878fcb86-5f95-49fc-bd4d-d3c68029b4d1 | CPython Docs | file://datasets/cpython/Doc/faq/programming.rst | unknown | edda7b58-bd69-4060-9295-d9036b4690eb | 2,139 | supabase-export-v2 | 89daaac28ea89a2a | There are (at least) three possible workarounds for this problem.
Guido van Rossum recommends avoiding all uses of ``from <module> import ...``,
and placing all code inside functions. Initializations of global variables and
class variables should use constants or built-in functions only. This means
everything from an i... | trusted_official_docs | CPython Docs | There are (at least) three possible workarounds for this problem.
Guido van Rossum recommends avoiding all uses of ``from <module> import ...``,
and placing all code inside functions. Initializations of global variables and
class variables should use constants or built-in functions only. This means
everything from an i... | There are (at least) three possible workarounds for this problem.
Guido van Rossum recommends avoiding all uses of ``from <module> import ...``,
and placing all code inside functions. Initializations of global variables and
class variables should use constants or built-in functions only. This means
everything from an i... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
88369218-72fd-4aa4-8aed-6937ccc8e9c2 | CPython Docs | file://datasets/cpython/Doc/faq/programming.rst | unknown | edda7b58-bd69-4060-9295-d9036b4690eb | 2,106 | supabase-export-v2 | bca061c7a9a59170 | work when the *station_id* is mutable, the class needs to define the :meth:`~object.__eq__` and :meth:`~object.__hash__` methods so that the cache can detect relevant attribute updates::
class Weather:
"Example with a mutable station identifier" | trusted_official_docs | CPython Docs | work when the *station_id* is mutable, the class needs to define the :meth:`~object.__eq__` and :meth:`~object.__hash__` methods so that the cache can detect relevant attribute updates::
class Weather:
"Example with a mutable station identifier" | work when the *station_id* is mutable, the class needs to define the :meth:`~object.__eq__` and :meth:`~object.__hash__` methods so that the cache can detect relevant attribute updates::
class Weather:
"Example with a mutable station identifier" | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
885b7651-d1e4-4472-9d20-bddc11a0b5d1 | CPython Docs | file://datasets/cpython/Doc/faq/programming.rst | unknown | edda7b58-bd69-4060-9295-d9036b4690eb | 1,800 | supabase-export-v2 | 72aaa5b07ec75ab3 | slash at the end of the parameter list means that both parameters are positional-only. Thus, calling :func:`divmod` with keyword arguments would lead to an error::
>>> divmod(x=3, y=4)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: divmod() takes no keyword arguments | trusted_official_docs | CPython Docs | slash at the end of the parameter list means that both parameters are positional-only. Thus, calling :func:`divmod` with keyword arguments would lead to an error::
>>> divmod(x=3, y=4)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: divmod() takes no keyword arguments | slash at the end of the parameter list means that both parameters are positional-only. Thus, calling :func:`divmod` with keyword arguments would lead to an error::
>>> divmod(x=3, y=4)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: divmod() takes no keyword arguments | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
88a4d658-e045-49f5-9438-3e8252c8452e | CPython Docs | file://datasets/cpython/Doc/faq/programming.rst | unknown | edda7b58-bd69-4060-9295-d9036b4690eb | 1,915 | supabase-export-v2 | acf192652ed7d0dd | lisp_list = ("like", ("this", ("example", None) ) )
If mutability is desired, you could use lists instead of tuples. Here the
analogue of a Lisp *car* is ``lisp_list[0]`` and the analogue of *cdr* is
``lisp_list[1]``. Only do this if you're sure you really need to, because it's
usually a lot slower than using Python li... | trusted_official_docs | CPython Docs | lisp_list = ("like", ("this", ("example", None) ) )
If mutability is desired, you could use lists instead of tuples. Here the
analogue of a Lisp *car* is ``lisp_list[0]`` and the analogue of *cdr* is
``lisp_list[1]``. Only do this if you're sure you really need to, because it's
usually a lot slower than using Python li... | lisp_list = ("like", ("this", ("example", None) ) )
If mutability is desired, you could use lists instead of tuples. Here the
analogue of a Lisp *car* is ``lisp_list[0]`` and the analogue of *cdr* is
``lisp_list[1]``. Only do this if you're sure you really need to, because it's
usually a lot slower than using Python li... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
891e7e37-bd11-4a18-8396-9a5be2fa4541 | CPython Docs | file://datasets/cpython/Doc/faq/programming.rst | unknown | edda7b58-bd69-4060-9295-d9036b4690eb | 1,661 | supabase-export-v2 | a32a3c474366c3f5 | Why do lambdas defined in a loop with different values all return the same result? ----------------------------------------------------------------------------------
Assume you use a for loop to define a few different lambdas (or even plain
functions), for example:: | trusted_official_docs | CPython Docs | Why do lambdas defined in a loop with different values all return the same result? ----------------------------------------------------------------------------------
Assume you use a for loop to define a few different lambdas (or even plain
functions), for example:: | Why do lambdas defined in a loop with different values all return the same result? ----------------------------------------------------------------------------------
Assume you use a for loop to define a few different lambdas (or even plain
functions), for example:: | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
89f2a51e-22dc-4a8b-8e10-753ee0c2ddb4 | CPython Docs | file://datasets/cpython/Doc/faq/programming.rst | unknown | edda7b58-bd69-4060-9295-d9036b4690eb | 1,891 | supabase-export-v2 | 52d4c330a60e7302 | What's a negative index? ------------------------
Python sequences are indexed with positive numbers and negative numbers. For
positive numbers 0 is the first index 1 is the second index and so forth. For
negative indices -1 is the last index and -2 is the penultimate (next to last)
index and so forth. Think of ``seq[-... | trusted_official_docs | CPython Docs | What's a negative index? ------------------------
Python sequences are indexed with positive numbers and negative numbers. For
positive numbers 0 is the first index 1 is the second index and so forth. For
negative indices -1 is the last index and -2 is the penultimate (next to last)
index and so forth. Think of ``seq[-... | What's a negative index? ------------------------
Python sequences are indexed with positive numbers and negative numbers. For
positive numbers 0 is the first index 1 is the second index and so forth. For
negative indices -1 is the last index and -2 is the penultimate (next to last)
index and so forth. Think of ``seq[-... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
8aa7f68d-63a3-4cad-a625-b9c2e7f721c0 | CPython Docs | file://datasets/cpython/Doc/faq/programming.rst | unknown | edda7b58-bd69-4060-9295-d9036b4690eb | 2,149 | supabase-export-v2 | 25fe0904206003c5 | When I edit an imported module and reimport it, the changes don't show up. Why does this happen? -------------------------------------------------------------------------------------------------
For reasons of efficiency as well as consistency, Python only reads the module
file on the first time a module is imported. I... | trusted_official_docs | CPython Docs | When I edit an imported module and reimport it, the changes don't show up. Why does this happen? -------------------------------------------------------------------------------------------------
For reasons of efficiency as well as consistency, Python only reads the module
file on the first time a module is imported. I... | When I edit an imported module and reimport it, the changes don't show up. Why does this happen? -------------------------------------------------------------------------------------------------
For reasons of efficiency as well as consistency, Python only reads the module
file on the first time a module is imported. I... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
8c1307df-2839-42ce-b0e2-7b5333e46e54 | CPython Docs | file://datasets/cpython/Doc/faq/programming.rst | unknown | edda7b58-bd69-4060-9295-d9036b4690eb | 1,997 | supabase-export-v2 | 4a9c7f472bcb5f09 | def __getattr__(self, name): return getattr(self._outfile, name)
Here the ``UpperOut`` class redefines the ``write()`` method to convert the
argument string to uppercase before calling the underlying
``self._outfile.write()`` method. All other methods are delegated to the
underlying ``self._outfile`` object. The delega... | trusted_official_docs | CPython Docs | def __getattr__(self, name): return getattr(self._outfile, name)
Here the ``UpperOut`` class redefines the ``write()`` method to convert the
argument string to uppercase before calling the underlying
``self._outfile.write()`` method. All other methods are delegated to the
underlying ``self._outfile`` object. The delega... | def __getattr__(self, name): return getattr(self._outfile, name)
Here the ``UpperOut`` class redefines the ``write()`` method to convert the
argument string to uppercase before calling the underlying
``self._outfile.write()`` method. All other methods are delegated to the
underlying ``self._outfile`` object. The delega... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
8c6ecd29-d6f6-4b5c-bc17-16adc5649edf | CPython Docs | file://datasets/cpython/Doc/faq/programming.rst | unknown | edda7b58-bd69-4060-9295-d9036b4690eb | 1,635 | supabase-export-v2 | b74dfcd5b24ee2b0 | C arrays; with a C compiler you can embed all your modules into a new program, which is then linked with the standard Python modules.
It works by scanning your source recursively for import statements (in both
forms) and looking for the modules in the standard Python path as well as in the
source directory (for built-i... | trusted_official_docs | CPython Docs | C arrays; with a C compiler you can embed all your modules into a new program, which is then linked with the standard Python modules.
It works by scanning your source recursively for import statements (in both
forms) and looking for the modules in the standard Python path as well as in the
source directory (for built-i... | C arrays; with a C compiler you can embed all your modules into a new program, which is then linked with the standard Python modules.
It works by scanning your source recursively for import statements (in both
forms) and looking for the modules in the standard Python path as well as in the
source directory (for built-i... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
8d83b2db-738d-4244-a65f-34d7a9f7ac6f | CPython Docs | file://datasets/cpython/Doc/faq/programming.rst | unknown | edda7b58-bd69-4060-9295-d9036b4690eb | 1,682 | supabase-export-v2 | d6f28ccc80b09dad | scope. Using one import per line makes it easy to add and delete module imports, but using multiple imports per line uses less screen space.
It's good practice if you import modules in the following order: | trusted_official_docs | CPython Docs | scope. Using one import per line makes it easy to add and delete module imports, but using multiple imports per line uses less screen space.
It's good practice if you import modules in the following order: | scope. Using one import per line makes it easy to add and delete module imports, but using multiple imports per line uses less screen space.
It's good practice if you import modules in the following order: | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
8dc5d714-8a9f-4f97-96b5-88854974ea59 | CPython Docs | file://datasets/cpython/Doc/faq/programming.rst | unknown | edda7b58-bd69-4060-9295-d9036b4690eb | 1,634 | supabase-export-v2 | b6bf832b0f6de3ec | tools that determine the set of modules required by a program and bind these modules together with a Python binary to produce a single executable.
One is to use the freeze tool, which is included in the Python source tree as
:source:`Tools/freeze`. It converts Python byte code to C arrays; with a C compiler you can
emb... | trusted_official_docs | CPython Docs | tools that determine the set of modules required by a program and bind these modules together with a Python binary to produce a single executable.
One is to use the freeze tool, which is included in the Python source tree as
:source:`Tools/freeze`. It converts Python byte code to C arrays; with a C compiler you can
emb... | tools that determine the set of modules required by a program and bind these modules together with a Python binary to produce a single executable.
One is to use the freeze tool, which is included in the Python source tree as
:source:`Tools/freeze`. It converts Python byte code to C arrays; with a C compiler you can
emb... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
8e3f4042-03c4-4889-a2ca-22ad34894198 | CPython Docs | file://datasets/cpython/Doc/faq/programming.rst | unknown | edda7b58-bd69-4060-9295-d9036b4690eb | 2,070 | supabase-export-v2 | 6ec0959dccca5d0b | >>> a = 10_000_000 >>> b = 5_000_000 >>> c = b + 5_000_000 >>> a is c False
>>> a = 'Python'
>>> b = 'Py'
>>> c = b + 'thon'
>>> a is c
False | trusted_official_docs | CPython Docs | >>> a = 10_000_000 >>> b = 5_000_000 >>> c = b + 5_000_000 >>> a is c False
>>> a = 'Python'
>>> b = 'Py'
>>> c = b + 'thon'
>>> a is c
False | >>> a = 10_000_000 >>> b = 5_000_000 >>> c = b + 5_000_000 >>> a is c False
>>> a = 'Python'
>>> b = 'Py'
>>> c = b + 'thon'
>>> a is c
False | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
9094c234-d7a3-4193-a764-d9a09d32198e | CPython Docs | file://datasets/cpython/Doc/faq/programming.rst | unknown | edda7b58-bd69-4060-9295-d9036b4690eb | 1,998 | supabase-export-v2 | 4dd00da91b053af7 | to the underlying ``self._outfile`` object. The delegation is accomplished via the :meth:`~object.__getattr__` method; consult :ref:`the language reference <attribute-access>` for more information about controlling attribute access.
Note that for more general cases delegation can get trickier. When attributes
must be s... | trusted_official_docs | CPython Docs | to the underlying ``self._outfile`` object. The delegation is accomplished via the :meth:`~object.__getattr__` method; consult :ref:`the language reference <attribute-access>` for more information about controlling attribute access.
Note that for more general cases delegation can get trickier. When attributes
must be s... | to the underlying ``self._outfile`` object. The delegation is accomplished via the :meth:`~object.__getattr__` method; consult :ref:`the language reference <attribute-access>` for more information about controlling attribute access.
Note that for more general cases delegation can get trickier. When attributes
must be s... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
91557af8-5e8e-46f5-bc9e-38684be7c852 | CPython Docs | file://datasets/cpython/Doc/faq/programming.rst | unknown | edda7b58-bd69-4060-9295-d9036b4690eb | 1,720 | supabase-export-v2 | d1e08524483ca64d | mutable object has changed from ``[]`` to ``[10]``. Since both the variables refer to the same object, using either name accesses the modified value ``[10]``.
If we instead assign an immutable object to ``x``:: | trusted_official_docs | CPython Docs | mutable object has changed from ``[]`` to ``[10]``. Since both the variables refer to the same object, using either name accesses the modified value ``[10]``.
If we instead assign an immutable object to ``x``:: | mutable object has changed from ``[]`` to ``[10]``. Since both the variables refer to the same object, using either name accesses the modified value ``[10]``.
If we instead assign an immutable object to ``x``:: | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
91dbc6d6-cae6-4d0b-b672-c70f5798017d | CPython Docs | file://datasets/cpython/Doc/faq/programming.rst | unknown | edda7b58-bd69-4060-9295-d9036b4690eb | 1,743 | supabase-export-v2 | 1939cac5147d5249 | How do you make a higher order function in Python? --------------------------------------------------
You have two choices: you can use nested scopes or you can use callable objects. For example, suppose you wanted to define ``linear(a,b)`` which returns a
function ``f(x)`` that computes the value ``a*x+b``. Using nest... | trusted_official_docs | CPython Docs | How do you make a higher order function in Python? --------------------------------------------------
You have two choices: you can use nested scopes or you can use callable objects. For example, suppose you wanted to define ``linear(a,b)`` which returns a
function ``f(x)`` that computes the value ``a*x+b``. Using nest... | How do you make a higher order function in Python? --------------------------------------------------
You have two choices: you can use nested scopes or you can use callable objects. For example, suppose you wanted to define ``linear(a,b)`` which returns a
function ``f(x)`` that computes the value ``a*x+b``. Using nest... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
921781af-0d5a-4464-9348-3221f6a6f2dc | CPython Docs | file://datasets/cpython/Doc/faq/programming.rst | unknown | edda7b58-bd69-4060-9295-d9036b4690eb | 1,928 | supabase-export-v2 | 2458659ed297e7da | The suggested approach is to create a list of the desired length first and then fill in each element with a newly created list::
A = [None] * 3
for i in range(3):
A[i] = [None] * 2 | trusted_official_docs | CPython Docs | The suggested approach is to create a list of the desired length first and then fill in each element with a newly created list::
A = [None] * 3
for i in range(3):
A[i] = [None] * 2 | The suggested approach is to create a list of the desired length first and then fill in each element with a newly created list::
A = [None] * 3
for i in range(3):
A[i] = [None] * 2 | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
944e03a9-96d9-4cf5-bf98-4e04d3f5217d | CPython Docs | file://datasets/cpython/Doc/faq/programming.rst | unknown | edda7b58-bd69-4060-9295-d9036b4690eb | 2,029 | supabase-export-v2 | 340df895f48f8b7c | In Python you have to write a single constructor that catches all cases using default arguments. For example::
class C:
def __init__(self, i=None):
if i is None:
print("No arguments")
else:
print("Argument is", i) | trusted_official_docs | CPython Docs | In Python you have to write a single constructor that catches all cases using default arguments. For example::
class C:
def __init__(self, i=None):
if i is None:
print("No arguments")
else:
print("Argument is", i) | In Python you have to write a single constructor that catches all cases using default arguments. For example::
class C:
def __init__(self, i=None):
if i is None:
print("No arguments")
else:
print("Argument is", i) | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
94b400de-8f1c-467f-960e-4865630ffa0f | CPython Docs | file://datasets/cpython/Doc/faq/programming.rst | unknown | edda7b58-bd69-4060-9295-d9036b4690eb | 2,117 | supabase-export-v2 | 74e6aceb276469d9 | module and Python has the ability (permissions, free space, and so on) to create a ``__pycache__`` subdirectory and write the compiled module to that subdirectory.
Running Python on a top-level script is not considered an import and no
``.pyc`` will be created. For example, if you have a top-level module
``foo.py`` tha... | trusted_official_docs | CPython Docs | module and Python has the ability (permissions, free space, and so on) to create a ``__pycache__`` subdirectory and write the compiled module to that subdirectory.
Running Python on a top-level script is not considered an import and no
``.pyc`` will be created. For example, if you have a top-level module
``foo.py`` tha... | module and Python has the ability (permissions, free space, and so on) to create a ``__pycache__`` subdirectory and write the compiled module to that subdirectory.
Running Python on a top-level script is not considered an import and no
``.pyc`` will be created. For example, if you have a top-level module
``foo.py`` tha... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
96607c90-49af-4625-afe9-8c8a317f4a7d | CPython Docs | file://datasets/cpython/Doc/faq/programming.rst | unknown | edda7b58-bd69-4060-9295-d9036b4690eb | 2,067 | supabase-export-v2 | a6a9483b8cd2d827 | a container that stores object references does not change object identity. After the list assignment ``s[0] = x``, it is guaranteed that ``s[0] is x``.
3) If an object is a singleton, it means that only one instance of that object
can exist. After the assignments ``a = None`` and ``b = None``, it is
guaranteed that `... | trusted_official_docs | CPython Docs | a container that stores object references does not change object identity. After the list assignment ``s[0] = x``, it is guaranteed that ``s[0] is x``.
3) If an object is a singleton, it means that only one instance of that object
can exist. After the assignments ``a = None`` and ``b = None``, it is
guaranteed that `... | a container that stores object references does not change object identity. After the list assignment ``s[0] = x``, it is guaranteed that ``s[0] is x``.
3) If an object is a singleton, it means that only one instance of that object
can exist. After the assignments ``a = None`` and ``b = None``, it is
guaranteed that `... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
977b6039-ab75-4f52-8695-142e41011719 | CPython Docs | file://datasets/cpython/Doc/faq/programming.rst | unknown | edda7b58-bd69-4060-9295-d9036b4690eb | 1,744 | supabase-export-v2 | f5d34f8a553fd7fe | can use callable objects. For example, suppose you wanted to define ``linear(a,b)`` which returns a function ``f(x)`` that computes the value ``a*x+b``. Using nested scopes::
def linear(a, b):
def result(x):
return a * x + b
return result | trusted_official_docs | CPython Docs | can use callable objects. For example, suppose you wanted to define ``linear(a,b)`` which returns a function ``f(x)`` that computes the value ``a*x+b``. Using nested scopes::
def linear(a, b):
def result(x):
return a * x + b
return result | can use callable objects. For example, suppose you wanted to define ``linear(a,b)`` which returns a function ``f(x)`` that computes the value ``a*x+b``. Using nested scopes::
def linear(a, b):
def result(x):
return a * x + b
return result | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
97fb9c36-637c-4df6-aa32-5ec3a4a974c9 | CPython Docs | file://datasets/cpython/Doc/faq/programming.rst | unknown | edda7b58-bd69-4060-9295-d9036b4690eb | 1,793 | supabase-export-v2 | 3bbf7ec4cb3bee0b | | |______ columns on screen # | | |__________ maximum of "iterations" # | |_________________ range on y axis # |____________________________ range on x axis
Don't try this at home, kids! | trusted_official_docs | CPython Docs | | |______ columns on screen # | | |__________ maximum of "iterations" # | |_________________ range on y axis # |____________________________ range on x axis
Don't try this at home, kids! | | |______ columns on screen # | | |__________ maximum of "iterations" # | |_________________ range on y axis # |____________________________ range on x axis
Don't try this at home, kids! | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
98131f00-bf8d-46c5-9526-16ce2da5b8f1 | CPython Docs | file://datasets/cpython/Doc/faq/programming.rst | unknown | edda7b58-bd69-4060-9295-d9036b4690eb | 1,824 | supabase-export-v2 | 6c64ca222f375e9b | use the built-in functions :func:`hex` or :func:`oct`. For fancy formatting, see the :ref:`f-strings` and :ref:`formatstrings` sections. For example, ``"{:04d}".format(144)`` yields ``'0144'`` and ``"{:.3f}".format(1.0/3.0)`` yields ``'0.333'``.
How do I modify a string in place? ---------------------------------- | trusted_official_docs | CPython Docs | use the built-in functions :func:`hex` or :func:`oct`. For fancy formatting, see the :ref:`f-strings` and :ref:`formatstrings` sections. For example, ``"{:04d}".format(144)`` yields ``'0144'`` and ``"{:.3f}".format(1.0/3.0)`` yields ``'0.333'``.
How do I modify a string in place? ---------------------------------- | use the built-in functions :func:`hex` or :func:`oct`. For fancy formatting, see the :ref:`f-strings` and :ref:`formatstrings` sections. For example, ``"{:04d}".format(144)`` yields ``'0144'`` and ``"{:.3f}".format(1.0/3.0)`` yields ``'0.333'``.
How do I modify a string in place? ---------------------------------- | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
9b3602ca-18de-4df6-85fa-04b60267d12d | CPython Docs | file://datasets/cpython/Doc/faq/programming.rst | unknown | edda7b58-bd69-4060-9295-d9036b4690eb | 2,024 | supabase-export-v2 | 943b059d910c7936 | If your code is structured so as to define one class (or tightly related class hierarchy) per module, this supplies the desired encapsulation.
How can I overload constructors (or methods) in Python? ------------------------------------------------------- | trusted_official_docs | CPython Docs | If your code is structured so as to define one class (or tightly related class hierarchy) per module, this supplies the desired encapsulation.
How can I overload constructors (or methods) in Python? ------------------------------------------------------- | If your code is structured so as to define one class (or tightly related class hierarchy) per module, this supplies the desired encapsulation.
How can I overload constructors (or methods) in Python? ------------------------------------------------------- | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
9b4a17f6-89f7-42e4-9101-659f17ef704d | CPython Docs | file://datasets/cpython/Doc/faq/programming.rst | unknown | edda7b58-bd69-4060-9295-d9036b4690eb | 1,803 | supabase-export-v2 | 0871d77bc747c487 | How do I specify hexadecimal and octal integers? ------------------------------------------------
To specify an octal digit, precede the octal value with a zero, and then a lower
or uppercase "o". For example, to set the variable "a" to the octal value "10"
(8 in decimal), type:: | trusted_official_docs | CPython Docs | How do I specify hexadecimal and octal integers? ------------------------------------------------
To specify an octal digit, precede the octal value with a zero, and then a lower
or uppercase "o". For example, to set the variable "a" to the octal value "10"
(8 in decimal), type:: | How do I specify hexadecimal and octal integers? ------------------------------------------------
To specify an octal digit, precede the octal value with a zero, and then a lower
or uppercase "o". For example, to set the variable "a" to the octal value "10"
(8 in decimal), type:: | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
9b9151ef-4c6f-47d1-a492-feeb8f8bcf88 | CPython Docs | file://datasets/cpython/Doc/faq/programming.rst | unknown | edda7b58-bd69-4060-9295-d9036b4690eb | 1,876 | supabase-export-v2 | 1d21884fe3b7a7ca | code significantly faster than when interpreted. If you are confident in your C programming skills, you can also :ref:`write a C extension module <extending-index>` yourself.
.. seealso::
The wiki page devoted to `performance tips
<https://wiki.python.org/moin/PythonSpeed/PerformanceTips>`_. | trusted_official_docs | CPython Docs | code significantly faster than when interpreted. If you are confident in your C programming skills, you can also :ref:`write a C extension module <extending-index>` yourself.
.. seealso::
The wiki page devoted to `performance tips
<https://wiki.python.org/moin/PythonSpeed/PerformanceTips>`_. | code significantly faster than when interpreted. If you are confident in your C programming skills, you can also :ref:`write a C extension module <extending-index>` yourself.
.. seealso::
The wiki page devoted to `performance tips
<https://wiki.python.org/moin/PythonSpeed/PerformanceTips>`_. | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
9bbdae40-11c0-437a-a55f-3ea3fa28c2a3 | CPython Docs | file://datasets/cpython/Doc/faq/programming.rst | unknown | edda7b58-bd69-4060-9295-d9036b4690eb | 1,961 | supabase-export-v2 | e6b2657c2511ea8a | even though ``result`` points to the same object that ``a_tuple[0]`` already points to, that final assignment still results in an error, because tuples are immutable.
I want to do a complicated sort: can you do a Schwartzian Transform in Python? --------------------------------------------------------------------------... | trusted_official_docs | CPython Docs | even though ``result`` points to the same object that ``a_tuple[0]`` already points to, that final assignment still results in an error, because tuples are immutable.
I want to do a complicated sort: can you do a Schwartzian Transform in Python? --------------------------------------------------------------------------... | even though ``result`` points to the same object that ``a_tuple[0]`` already points to, that final assignment still results in an error, because tuples are immutable.
I want to do a complicated sort: can you do a Schwartzian Transform in Python? --------------------------------------------------------------------------... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
9c54d9ee-d2ca-4e69-aa5e-e8c2f9692311 | CPython Docs | file://datasets/cpython/Doc/faq/programming.rst | unknown | edda7b58-bd69-4060-9295-d9036b4690eb | 1,730 | supabase-export-v2 | 709c65e17b3eae05 | alias between an argument name in the caller and callee, and consequently no call-by-reference. You can achieve the desired effect in a number of ways.
1) By returning a tuple of the results:: | trusted_official_docs | CPython Docs | alias between an argument name in the caller and callee, and consequently no call-by-reference. You can achieve the desired effect in a number of ways.
1) By returning a tuple of the results:: | alias between an argument name in the caller and callee, and consequently no call-by-reference. You can achieve the desired effect in a number of ways.
1) By returning a tuple of the results:: | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
9c75f722-c533-4bcc-8ec3-11f2c5f02ad4 | CPython Docs | file://datasets/cpython/Doc/faq/programming.rst | unknown | edda7b58-bd69-4060-9295-d9036b4690eb | 1,704 | supabase-export-v2 | c8309df496a176ca | as a tuple and the keyword arguments as a dictionary. You can then pass these arguments when calling another function by using ``*`` and ``**``::
def f(x, *args, **kwargs):
... kwargs['width'] = '14.3c'
... g(x, *args, **kwargs) | trusted_official_docs | CPython Docs | as a tuple and the keyword arguments as a dictionary. You can then pass these arguments when calling another function by using ``*`` and ``**``::
def f(x, *args, **kwargs):
... kwargs['width'] = '14.3c'
... g(x, *args, **kwargs) | as a tuple and the keyword arguments as a dictionary. You can then pass these arguments when calling another function by using ``*`` and ``**``::
def f(x, *args, **kwargs):
... kwargs['width'] = '14.3c'
... g(x, *args, **kwargs) | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
9f81913b-df59-4a39-89b2-739e40377bb0 | CPython Docs | file://datasets/cpython/Doc/faq/programming.rst | unknown | edda7b58-bd69-4060-9295-d9036b4690eb | 1,804 | supabase-export-v2 | ebfe68177d763d95 | a zero, and then a lower or uppercase "o". For example, to set the variable "a" to the octal value "10" (8 in decimal), type::
>>> a = 0o10
>>> a
8 | trusted_official_docs | CPython Docs | a zero, and then a lower or uppercase "o". For example, to set the variable "a" to the octal value "10" (8 in decimal), type::
>>> a = 0o10
>>> a
8 | a zero, and then a lower or uppercase "o". For example, to set the variable "a" to the octal value "10" (8 in decimal), type::
>>> a = 0o10
>>> a
8 | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
a301497f-d9f5-4df0-a143-36fa3a475a53 | CPython Docs | file://datasets/cpython/Doc/faq/programming.rst | unknown | edda7b58-bd69-4060-9295-d9036b4690eb | 1,850 | supabase-export-v2 | 7054f95d3a22009f | values using :func:`int` or :func:`float`. :meth:`!split` supports an optional "sep" parameter which is useful if the line uses something other than whitespace as a separator.
For more complicated input parsing, regular expressions are more powerful
than C's ``sscanf`` and better suited for the task. | trusted_official_docs | CPython Docs | values using :func:`int` or :func:`float`. :meth:`!split` supports an optional "sep" parameter which is useful if the line uses something other than whitespace as a separator.
For more complicated input parsing, regular expressions are more powerful
than C's ``sscanf`` and better suited for the task. | values using :func:`int` or :func:`float`. :meth:`!split` supports an optional "sep" parameter which is useful if the line uses something other than whitespace as a separator.
For more complicated input parsing, regular expressions are more powerful
than C's ``sscanf`` and better suited for the task. | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
a36e56ee-1270-45e6-b0ae-3f39f0fd7c90 | CPython Docs | file://datasets/cpython/Doc/faq/programming.rst | unknown | edda7b58-bd69-4060-9295-d9036b4690eb | 1,958 | supabase-export-v2 | 1dd5b22d04388f97 | the assignment is a no-op, since it is a pointer to the same object that ``a_list`` was previously pointing to, but the assignment still happens.
Thus, in our tuple example what is happening is equivalent to:: | trusted_official_docs | CPython Docs | the assignment is a no-op, since it is a pointer to the same object that ``a_list`` was previously pointing to, but the assignment still happens.
Thus, in our tuple example what is happening is equivalent to:: | the assignment is a no-op, since it is a pointer to the same object that ``a_list`` was previously pointing to, but the assignment still happens.
Thus, in our tuple example what is happening is equivalent to:: | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
a39c3c95-63f1-47b4-9913-c7ab8aa0c1a1 | CPython Docs | file://datasets/cpython/Doc/faq/programming.rst | unknown | edda7b58-bd69-4060-9295-d9036b4690eb | 1,761 | supabase-export-v2 | 68d1cfda23bbfd8b | In general, try :func:`copy.copy` or :func:`copy.deepcopy` for the general case. Not all objects can be copied, but most can.
Some objects can be copied more easily. Dictionaries have a :meth:`~dict.copy`
method:: | trusted_official_docs | CPython Docs | In general, try :func:`copy.copy` or :func:`copy.deepcopy` for the general case. Not all objects can be copied, but most can.
Some objects can be copied more easily. Dictionaries have a :meth:`~dict.copy`
method:: | In general, try :func:`copy.copy` or :func:`copy.deepcopy` for the general case. Not all objects can be copied, but most can.
Some objects can be copied more easily. Dictionaries have a :meth:`~dict.copy`
method:: | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
a564ab1c-6e05-4c42-8763-7e9217b03d5e | CPython Docs | file://datasets/cpython/Doc/faq/programming.rst | unknown | edda7b58-bd69-4060-9295-d9036b4690eb | 1,968 | supabase-export-v2 | 8273f2020ffb0356 | What is a class? ----------------
A class is the particular object type created by executing a class statement. Class objects are used as templates to create instance objects, which embody
both the data (attributes) and code (methods) specific to a datatype. | trusted_official_docs | CPython Docs | What is a class? ----------------
A class is the particular object type created by executing a class statement. Class objects are used as templates to create instance objects, which embody
both the data (attributes) and code (methods) specific to a datatype. | What is a class? ----------------
A class is the particular object type created by executing a class statement. Class objects are used as templates to create instance objects, which embody
both the data (attributes) and code (methods) specific to a datatype. | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
a6b7ec8e-3c5d-4aef-8d4e-9b1c5397e2f7 | CPython Docs | file://datasets/cpython/Doc/faq/programming.rst | unknown | edda7b58-bd69-4060-9295-d9036b4690eb | 1,962 | supabase-export-v2 | 3af0e838ea8ea02f | I want to do a complicated sort: can you do a Schwartzian Transform in Python? ------------------------------------------------------------------------------
The technique, attributed to Randal Schwartz of the Perl community, sorts the
elements of a list by a metric which maps each element to its "sort value". In
Pytho... | trusted_official_docs | CPython Docs | I want to do a complicated sort: can you do a Schwartzian Transform in Python? ------------------------------------------------------------------------------
The technique, attributed to Randal Schwartz of the Perl community, sorts the
elements of a list by a metric which maps each element to its "sort value". In
Pytho... | I want to do a complicated sort: can you do a Schwartzian Transform in Python? ------------------------------------------------------------------------------
The technique, attributed to Randal Schwartz of the Perl community, sorts the
elements of a list by a metric which maps each element to its "sort value". In
Pytho... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
a7285683-dae2-4cb1-96ea-d89f2919f227 | CPython Docs | file://datasets/cpython/Doc/faq/programming.rst | unknown | edda7b58-bd69-4060-9295-d9036b4690eb | 1,827 | supabase-export-v2 | 1cf5053a854f4974 | import io >>> s = "Hello, world" >>> sio = io.StringIO(s) >>> sio.getvalue() 'Hello, world' >>> sio.seek(7) 7 >>> sio.write("there!") 6 >>> sio.getvalue() 'Hello, there!'
>>> import array
>>> a = array.array('w', s)
>>> print(a)
array('w', 'Hello, world')
>>> a[0] = 'y'
>>> print(a)
array('w', 'yello, world')
>>... | trusted_official_docs | CPython Docs | import io >>> s = "Hello, world" >>> sio = io.StringIO(s) >>> sio.getvalue() 'Hello, world' >>> sio.seek(7) 7 >>> sio.write("there!") 6 >>> sio.getvalue() 'Hello, there!'
>>> import array
>>> a = array.array('w', s)
>>> print(a)
array('w', 'Hello, world')
>>> a[0] = 'y'
>>> print(a)
array('w', 'yello, world')
>>... | import io >>> s = "Hello, world" >>> sio = io.StringIO(s) >>> sio.getvalue() 'Hello, world' >>> sio.seek(7) 7 >>> sio.write("there!") 6 >>> sio.getvalue() 'Hello, there!'
>>> import array
>>> a = array.array('w', s)
>>> print(a)
array('w', 'Hello, world')
>>> a[0] = 'y'
>>> print(a)
array('w', 'yello, world')
>>... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
a83029e7-6931-4ff6-b51b-3bfd95a2bfdd | CPython Docs | file://datasets/cpython/Doc/faq/programming.rst | unknown | edda7b58-bd69-4060-9295-d9036b4690eb | 1,636 | supabase-export-v2 | 7452eccb0a3ad64a | the generated C code and links it with the rest of the Python interpreter to form a self-contained binary which acts exactly like your script.
The following packages can help with the creation of console and GUI
executables: | trusted_official_docs | CPython Docs | the generated C code and links it with the rest of the Python interpreter to form a self-contained binary which acts exactly like your script.
The following packages can help with the creation of console and GUI
executables: | the generated C code and links it with the rest of the Python interpreter to form a self-contained binary which acts exactly like your script.
The following packages can help with the creation of console and GUI
executables: | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
a859f4d3-0496-4eb7-811d-1abca88adaf0 | CPython Docs | file://datasets/cpython/Doc/faq/programming.rst | unknown | edda7b58-bd69-4060-9295-d9036b4690eb | 1,892 | supabase-export-v2 | 6339cc269c2e2512 | -1 is the last index and -2 is the penultimate (next to last) index and so forth. Think of ``seq[-n]`` as the same as ``seq[len(seq)-n]``.
Using negative indices can be very convenient. For example ``S[:-1]`` is all of
the string except for its last character, which is useful for removing the
trailing newline from a st... | trusted_official_docs | CPython Docs | -1 is the last index and -2 is the penultimate (next to last) index and so forth. Think of ``seq[-n]`` as the same as ``seq[len(seq)-n]``.
Using negative indices can be very convenient. For example ``S[:-1]`` is all of
the string except for its last character, which is useful for removing the
trailing newline from a st... | -1 is the last index and -2 is the penultimate (next to last) index and so forth. Think of ``seq[-n]`` as the same as ``seq[len(seq)-n]``.
Using negative indices can be very convenient. For example ``S[:-1]`` is all of
the string except for its last character, which is useful for removing the
trailing newline from a st... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
a9a15f19-25f1-41bc-9ebe-eba32da601ef | CPython Docs | file://datasets/cpython/Doc/faq/programming.rst | unknown | edda7b58-bd69-4060-9295-d9036b4690eb | 1,694 | supabase-export-v2 | c66427862713de33 | function is defined. If that object is changed, like the dictionary in this example, subsequent calls to the function will refer to this changed object.
By definition, immutable objects such as numbers, strings, tuples, and ``None``,
are safe from change. Changes to mutable objects such as dictionaries, lists,
and clas... | trusted_official_docs | CPython Docs | function is defined. If that object is changed, like the dictionary in this example, subsequent calls to the function will refer to this changed object.
By definition, immutable objects such as numbers, strings, tuples, and ``None``,
are safe from change. Changes to mutable objects such as dictionaries, lists,
and clas... | function is defined. If that object is changed, like the dictionary in this example, subsequent calls to the function will refer to this changed object.
By definition, immutable objects such as numbers, strings, tuples, and ``None``,
are safe from change. Changes to mutable objects such as dictionaries, lists,
and clas... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
aafa1d90-5da0-4299-bce9-8dc1be5a9e1a | CPython Docs | file://datasets/cpython/Doc/faq/programming.rst | unknown | edda7b58-bd69-4060-9295-d9036b4690eb | 1,700 | supabase-export-v2 | 30de4c6cbe377d8d | Callers can only provide two parameters and optionally pass _cache by keyword def expensive(arg1, arg2, *, _cache={}): if (arg1, arg2) in _cache: return _cache[(arg1, arg2)]
# Calculate the value
result = ... expensive computation ... _cache[(arg1, arg2)] = result # Store result in the cache
return result | trusted_official_docs | CPython Docs | Callers can only provide two parameters and optionally pass _cache by keyword def expensive(arg1, arg2, *, _cache={}): if (arg1, arg2) in _cache: return _cache[(arg1, arg2)]
# Calculate the value
result = ... expensive computation ... _cache[(arg1, arg2)] = result # Store result in the cache
return result | Callers can only provide two parameters and optionally pass _cache by keyword def expensive(arg1, arg2, *, _cache={}): if (arg1, arg2) in _cache: return _cache[(arg1, arg2)]
# Calculate the value
result = ... expensive computation ... _cache[(arg1, arg2)] = result # Store result in the cache
return result | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
ab243ef8-9885-4b04-8443-365f02733ba4 | CPython Docs | file://datasets/cpython/Doc/faq/programming.rst | unknown | edda7b58-bd69-4060-9295-d9036b4690eb | 1,947 | supabase-export-v2 | 94f1548b88b45ec7 | Under the covers, what this augmented assignment statement is doing is approximately this::
>>> result = a_tuple[0] + 1
>>> a_tuple[0] = result
Traceback (most recent call last):
... TypeError: 'tuple' object does not support item assignment | trusted_official_docs | CPython Docs | Under the covers, what this augmented assignment statement is doing is approximately this::
>>> result = a_tuple[0] + 1
>>> a_tuple[0] = result
Traceback (most recent call last):
... TypeError: 'tuple' object does not support item assignment | Under the covers, what this augmented assignment statement is doing is approximately this::
>>> result = a_tuple[0] + 1
>>> a_tuple[0] = result
Traceback (most recent call last):
... TypeError: 'tuple' object does not support item assignment | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
ab6c8cb1-b509-4e95-8da4-53da15b7ba9f | CPython Docs | file://datasets/cpython/Doc/faq/programming.rst | unknown | edda7b58-bd69-4060-9295-d9036b4690eb | 1,880 | supabase-export-v2 | df17a8d6f5266ee5 | together is inefficient as each concatenation creates a new object. In the general case, the total runtime cost is quadratic in the total string length.
To accumulate many :class:`str` objects, the recommended idiom is to place
them into a list and call :meth:`str.join` at the end:: | trusted_official_docs | CPython Docs | together is inefficient as each concatenation creates a new object. In the general case, the total runtime cost is quadratic in the total string length.
To accumulate many :class:`str` objects, the recommended idiom is to place
them into a list and call :meth:`str.join` at the end:: | together is inefficient as each concatenation creates a new object. In the general case, the total runtime cost is quadratic in the total string length.
To accumulate many :class:`str` objects, the recommended idiom is to place
them into a list and call :meth:`str.join` at the end:: | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
ad11c83c-bac5-4367-a54c-4f216f0884c6 | CPython Docs | file://datasets/cpython/Doc/faq/programming.rst | unknown | edda7b58-bd69-4060-9295-d9036b4690eb | 1,999 | supabase-export-v2 | 3c17ae6ad1fe272b | the class must define a :meth:`~object.__setattr__` method too, and it must do so carefully. The basic implementation of :meth:`!__setattr__` is roughly equivalent to the following::
class X:
... def __setattr__(self, name, value):
self.__dict__[name] = value
... | trusted_official_docs | CPython Docs | the class must define a :meth:`~object.__setattr__` method too, and it must do so carefully. The basic implementation of :meth:`!__setattr__` is roughly equivalent to the following::
class X:
... def __setattr__(self, name, value):
self.__dict__[name] = value
... | the class must define a :meth:`~object.__setattr__` method too, and it must do so carefully. The basic implementation of :meth:`!__setattr__` is roughly equivalent to the following::
class X:
... def __setattr__(self, name, value):
self.__dict__[name] = value
... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
aee97799-1cac-428e-b30b-3ce0be003ac2 | CPython Docs | file://datasets/cpython/Doc/faq/programming.rst | unknown | edda7b58-bd69-4060-9295-d9036b4690eb | 1,814 | supabase-export-v2 | bb55b32fabedf268 | Trying to lookup an ``int`` literal attribute in the normal manner gives a :exc:`SyntaxError` because the period is seen as a decimal point::
>>> 1.__class__
File "<stdin>", line 1
1.__class__
^
SyntaxError: invalid decimal literal | trusted_official_docs | CPython Docs | Trying to lookup an ``int`` literal attribute in the normal manner gives a :exc:`SyntaxError` because the period is seen as a decimal point::
>>> 1.__class__
File "<stdin>", line 1
1.__class__
^
SyntaxError: invalid decimal literal | Trying to lookup an ``int`` literal attribute in the normal manner gives a :exc:`SyntaxError` because the period is seen as a decimal point::
>>> 1.__class__
File "<stdin>", line 1
1.__class__
^
SyntaxError: invalid decimal literal | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
af03d5a0-02a5-4236-a450-d2eb54d1d83f | CPython Docs | file://datasets/cpython/Doc/faq/programming.rst | unknown | edda7b58-bd69-4060-9295-d9036b4690eb | 1,702 | supabase-export-v2 | 576f04e9768541a4 | You could use a global variable containing a dictionary instead of the default value; it's a matter of taste.
How can I pass optional or keyword parameters from one function to another? --------------------------------------------------------------------------- | trusted_official_docs | CPython Docs | You could use a global variable containing a dictionary instead of the default value; it's a matter of taste.
How can I pass optional or keyword parameters from one function to another? --------------------------------------------------------------------------- | You could use a global variable containing a dictionary instead of the default value; it's a matter of taste.
How can I pass optional or keyword parameters from one function to another? --------------------------------------------------------------------------- | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
b06f4ff8-1179-43de-ab35-325bf27d58aa | CPython Docs | file://datasets/cpython/Doc/faq/programming.rst | unknown | edda7b58-bd69-4060-9295-d9036b4690eb | 1,693 | supabase-export-v2 | 38f9c426104e7f61 | contains a single item. The second time, ``mydict`` contains two items because when ``foo()`` begins executing, ``mydict`` starts out with an item already in it.
It is often expected that a function call creates new objects for default
values. This is not what happens. Default values are created exactly once, when
the ... | trusted_official_docs | CPython Docs | contains a single item. The second time, ``mydict`` contains two items because when ``foo()`` begins executing, ``mydict`` starts out with an item already in it.
It is often expected that a function call creates new objects for default
values. This is not what happens. Default values are created exactly once, when
the ... | contains a single item. The second time, ``mydict`` contains two items because when ``foo()`` begins executing, ``mydict`` starts out with an item already in it.
It is often expected that a function call creates new objects for default
values. This is not what happens. Default values are created exactly once, when
the ... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
b0eafbcd-4870-46ef-bab9-440d40e49521 | CPython Docs | file://datasets/cpython/Doc/faq/programming.rst | unknown | edda7b58-bd69-4060-9295-d9036b4690eb | 1,965 | supabase-export-v2 | e9200430b74803df | How can I sort one list by values from another list? ----------------------------------------------------
Merge them into an iterator of tuples, sort the resulting list, and then pick
out the element you want. | trusted_official_docs | CPython Docs | How can I sort one list by values from another list? ----------------------------------------------------
Merge them into an iterator of tuples, sort the resulting list, and then pick
out the element you want. | How can I sort one list by values from another list? ----------------------------------------------------
Merge them into an iterator of tuples, sort the resulting list, and then pick
out the element you want. | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
b1490f89-6138-4a5e-8292-4352d1871727 | CPython Docs | file://datasets/cpython/Doc/faq/programming.rst | unknown | edda7b58-bd69-4060-9295-d9036b4690eb | 2,084 | supabase-export-v2 | d6e1c97ab729ebc9 | instead of the :meth:`~object.__init__` method. The latter only runs *after* an instance is created, which is too late to alter data in an immutable instance.
All of these immutable classes have a different signature than their
parent class: | trusted_official_docs | CPython Docs | instead of the :meth:`~object.__init__` method. The latter only runs *after* an instance is created, which is too late to alter data in an immutable instance.
All of these immutable classes have a different signature than their
parent class: | instead of the :meth:`~object.__init__` method. The latter only runs *after* an instance is created, which is too late to alter data in an immutable instance.
All of these immutable classes have a different signature than their
parent class: | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
b18d1dbe-fbcb-497c-80c2-9e30b701b719 | CPython Docs | file://datasets/cpython/Doc/faq/programming.rst | unknown | edda7b58-bd69-4060-9295-d9036b4690eb | 2,079 | supabase-export-v2 | d4a0397b53c2270b | def pop(self, key, default=_sentinel): if key in self: value = self[key] del self[key] return value if default is _sentinel: raise KeyError(key) return default
3) Container implementations sometimes need to augment equality tests with
identity tests. This prevents the code from being confused by objects
such as ``flo... | trusted_official_docs | CPython Docs | def pop(self, key, default=_sentinel): if key in self: value = self[key] del self[key] return value if default is _sentinel: raise KeyError(key) return default
3) Container implementations sometimes need to augment equality tests with
identity tests. This prevents the code from being confused by objects
such as ``flo... | def pop(self, key, default=_sentinel): if key in self: value = self[key] del self[key] return value if default is _sentinel: raise KeyError(key) return default
3) Container implementations sometimes need to augment equality tests with
identity tests. This prevents the code from being confused by objects
such as ``flo... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
b197a1df-1d6f-4c50-bcbf-09d71218315f | CPython Docs | file://datasets/cpython/Doc/faq/programming.rst | unknown | edda7b58-bd69-4060-9295-d9036b4690eb | 1,653 | supabase-export-v2 | 229388afdb32e248 | >>> x = 10 >>> def foobar(): ... global x ... print(x) ... x += 1 ... >>> foobar() 10
This explicit declaration is required in order to remind you that (unlike the
superficially analogous situation with class and instance variables) you are
actually modifying the value of the variable in the outer scope: | trusted_official_docs | CPython Docs | >>> x = 10 >>> def foobar(): ... global x ... print(x) ... x += 1 ... >>> foobar() 10
This explicit declaration is required in order to remind you that (unlike the
superficially analogous situation with class and instance variables) you are
actually modifying the value of the variable in the outer scope: | >>> x = 10 >>> def foobar(): ... global x ... print(x) ... x += 1 ... >>> foobar() 10
This explicit declaration is required in order to remind you that (unlike the
superficially analogous situation with class and instance variables) you are
actually modifying the value of the variable in the outer scope: | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
b23c960a-270b-44ea-a965-72641a3fbd74 | CPython Docs | file://datasets/cpython/Doc/faq/programming.rst | unknown | edda7b58-bd69-4060-9295-d9036b4690eb | 2,036 | supabase-export-v2 | e23699f98c490aa3 | two leading underscores, at most one trailing underscore) is textually replaced with ``_classname__spam``, where ``classname`` is the current class name with any leading underscores stripped.
The identifier can be used unchanged within the class, but to access it outside
the class, the mangled name must be used: | trusted_official_docs | CPython Docs | two leading underscores, at most one trailing underscore) is textually replaced with ``_classname__spam``, where ``classname`` is the current class name with any leading underscores stripped.
The identifier can be used unchanged within the class, but to access it outside
the class, the mangled name must be used: | two leading underscores, at most one trailing underscore) is textually replaced with ``_classname__spam``, where ``classname`` is the current class name with any leading underscores stripped.
The identifier can be used unchanged within the class, but to access it outside
the class, the mangled name must be used: | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
b3025bac-e925-4905-aaa4-87270b1704be | CPython Docs | file://datasets/cpython/Doc/faq/programming.rst | unknown | edda7b58-bd69-4060-9295-d9036b4690eb | 2,126 | supabase-export-v2 | fbb0caea59fe4397 | Many modules that are usually used by importing them also provide a command-line interface or a self-test, and only execute this code after checking ``__name__``::
def main():
print('Running test...')
... | trusted_official_docs | CPython Docs | Many modules that are usually used by importing them also provide a command-line interface or a self-test, and only execute this code after checking ``__name__``::
def main():
print('Running test...')
... | Many modules that are usually used by importing them also provide a command-line interface or a self-test, and only execute this code after checking ``__name__``::
def main():
print('Running test...')
... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
b3dfe092-4912-47b9-ba59-93e9d880debd | CPython Docs | file://datasets/cpython/Doc/faq/programming.rst | unknown | edda7b58-bd69-4060-9295-d9036b4690eb | 1,719 | supabase-export-v2 | 32ec80f89c69fb3c | only one object (the list), and both ``x`` and ``y`` refer to it. 2) Lists are :term:`mutable`, which means that you can change their content.
After the call to :meth:`~sequence.append`, the content of the mutable object has
changed from ``[]`` to ``[10]``. Since both the variables refer to the same
object, using eithe... | trusted_official_docs | CPython Docs | only one object (the list), and both ``x`` and ``y`` refer to it. 2) Lists are :term:`mutable`, which means that you can change their content.
After the call to :meth:`~sequence.append`, the content of the mutable object has
changed from ``[]`` to ``[10]``. Since both the variables refer to the same
object, using eithe... | only one object (the list), and both ``x`` and ``y`` refer to it. 2) Lists are :term:`mutable`, which means that you can change their content.
After the call to :meth:`~sequence.append`, the content of the mutable object has
changed from ``[]`` to ``[10]``. Since both the variables refer to the same
object, using eithe... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
b5d003f4-024d-4594-82d7-43630d23988f | CPython Docs | file://datasets/cpython/Doc/faq/programming.rst | unknown | edda7b58-bd69-4060-9295-d9036b4690eb | 2,054 | supabase-export-v2 | 8020a44e5e04580c | How do I get a list of all instances of a given class? ------------------------------------------------------
Python does not keep track of all instances of a class (or of a built-in type). You can program the class's constructor to keep track of all instances by
keeping a list of weak references to each instance. | trusted_official_docs | CPython Docs | How do I get a list of all instances of a given class? ------------------------------------------------------
Python does not keep track of all instances of a class (or of a built-in type). You can program the class's constructor to keep track of all instances by
keeping a list of weak references to each instance. | How do I get a list of all instances of a given class? ------------------------------------------------------
Python does not keep track of all instances of a class (or of a built-in type). You can program the class's constructor to keep track of all instances by
keeping a list of weak references to each instance. | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
b7304708-cb3a-4b11-bbaf-008a32e7a35b | CPython Docs | file://datasets/cpython/Doc/faq/programming.rst | unknown | edda7b58-bd69-4060-9295-d9036b4690eb | 1,630 | supabase-export-v2 | cdf6660ff19b1da0 | `Ruff <https://docs.astral.sh/ruff/>`__, `Pylint <https://pylint.readthedocs.io/>`__ and `Pyflakes <https://github.com/PyCQA/pyflakes>`__ do basic checking that will help you catch bugs sooner.
Static type checkers such as `mypy <https://mypy-lang.org/>`__,
`ty <https://docs.astral.sh/ty/>`__,
`Pyrefly <https://pyrefly... | trusted_official_docs | CPython Docs | `Ruff <https://docs.astral.sh/ruff/>`__, `Pylint <https://pylint.readthedocs.io/>`__ and `Pyflakes <https://github.com/PyCQA/pyflakes>`__ do basic checking that will help you catch bugs sooner.
Static type checkers such as `mypy <https://mypy-lang.org/>`__,
`ty <https://docs.astral.sh/ty/>`__,
`Pyrefly <https://pyrefly... | `Ruff <https://docs.astral.sh/ruff/>`__, `Pylint <https://pylint.readthedocs.io/>`__ and `Pyflakes <https://github.com/PyCQA/pyflakes>`__ do basic checking that will help you catch bugs sooner.
Static type checkers such as `mypy <https://mypy-lang.org/>`__,
`ty <https://docs.astral.sh/ty/>`__,
`Pyrefly <https://pyrefly... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
b77795b5-ad99-4bab-a5a9-fc5644ede9af | CPython Docs | file://datasets/cpython/Doc/faq/programming.rst | unknown | edda7b58-bd69-4060-9295-d9036b4690eb | 1,740 | supabase-export-v2 | 05f461056754f1f3 | Namespace ... args.b = args.b + 1 # change object in-place ... >>> args = Namespace(a='old-value', b=99) >>> func4(args) >>> vars(args) {'a': 'new-value', 'b': 100}
There's almost never a good reason to get this complicated. | trusted_official_docs | CPython Docs | Namespace ... args.b = args.b + 1 # change object in-place ... >>> args = Namespace(a='old-value', b=99) >>> func4(args) >>> vars(args) {'a': 'new-value', 'b': 100}
There's almost never a good reason to get this complicated. | Namespace ... args.b = args.b + 1 # change object in-place ... >>> args = Namespace(a='old-value', b=99) >>> func4(args) >>> vars(args) {'a': 'new-value', 'b': 100}
There's almost never a good reason to get this complicated. | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
b86aa688-f2d6-4087-82a8-b6b296f1ef30 | CPython Docs | file://datasets/cpython/Doc/faq/programming.rst | unknown | edda7b58-bd69-4060-9295-d9036b4690eb | 1,926 | supabase-export-v2 | 4cf5bf920369524c | >>> A[0][0] = 5 >>> A [[5, None], [5, None], [5, None]]
The reason is that replicating a list with ``*`` doesn't create copies, it only
creates references to the existing objects. The ``*3`` creates a list
containing 3 references to the same list of length two. Changes to one row will
show in all rows, which is almost ... | trusted_official_docs | CPython Docs | >>> A[0][0] = 5 >>> A [[5, None], [5, None], [5, None]]
The reason is that replicating a list with ``*`` doesn't create copies, it only
creates references to the existing objects. The ``*3`` creates a list
containing 3 references to the same list of length two. Changes to one row will
show in all rows, which is almost ... | >>> A[0][0] = 5 >>> A [[5, None], [5, None], [5, None]]
The reason is that replicating a list with ``*`` doesn't create copies, it only
creates references to the existing objects. The ``*3`` creates a list
containing 3 references to the same list of length two. Changes to one row will
show in all rows, which is almost ... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
bb5e731e-147b-4ded-92f2-cb3bd00f20ab | CPython Docs | file://datasets/cpython/Doc/faq/programming.rst | unknown | edda7b58-bd69-4060-9295-d9036b4690eb | 1,688 | supabase-export-v2 | fe899af96e67406d | of the modules at the top of the file. In this case, importing the correct modules in the corresponding platform-specific code is a good option.
Only move imports into a local scope, such as inside a function definition, if
it's necessary to solve a problem such as avoiding a circular import or are
trying to reduce the... | trusted_official_docs | CPython Docs | of the modules at the top of the file. In this case, importing the correct modules in the corresponding platform-specific code is a good option.
Only move imports into a local scope, such as inside a function definition, if
it's necessary to solve a problem such as avoiding a circular import or are
trying to reduce the... | of the modules at the top of the file. In this case, importing the correct modules in the corresponding platform-specific code is a good option.
Only move imports into a local scope, such as inside a function definition, if
it's necessary to solve a problem such as avoiding a circular import or are
trying to reduce the... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
bbd1fd13-617e-48f7-acd3-02d6a7fa3397 | CPython Docs | file://datasets/cpython/Doc/faq/programming.rst | unknown | edda7b58-bd69-4060-9295-d9036b4690eb | 1,809 | supabase-export-v2 | 635e7d1bb461a772 | It's primarily driven by the desire that ``i % j`` have the same sign as ``j``. If you want that, and also want::
i == (i // j) * j + (i % j) | trusted_official_docs | CPython Docs | It's primarily driven by the desire that ``i % j`` have the same sign as ``j``. If you want that, and also want::
i == (i // j) * j + (i % j) | It's primarily driven by the desire that ``i % j`` have the same sign as ``j``. If you want that, and also want::
i == (i // j) * j + (i % j) | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
bbeac906-6f77-4ea2-8fa8-e4994a69b43d | CPython Docs | file://datasets/cpython/Doc/faq/programming.rst | unknown | edda7b58-bd69-4060-9295-d9036b4690eb | 1,954 | supabase-export-v2 | 5b861342aac6aa31 | is equivalent to calling :meth:`~sequence.extend` on the list and returning the list. That's why we say that for lists, ``+=`` is a "shorthand" for :meth:`list.extend`::
>>> a_list = []
>>> a_list += [1]
>>> a_list
[1] | trusted_official_docs | CPython Docs | is equivalent to calling :meth:`~sequence.extend` on the list and returning the list. That's why we say that for lists, ``+=`` is a "shorthand" for :meth:`list.extend`::
>>> a_list = []
>>> a_list += [1]
>>> a_list
[1] | is equivalent to calling :meth:`~sequence.extend` on the list and returning the list. That's why we say that for lists, ``+=`` is a "shorthand" for :meth:`list.extend`::
>>> a_list = []
>>> a_list += [1]
>>> a_list
[1] | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
bd33f88b-15b9-45ce-b192-5fd44b6c8d05 | CPython Docs | file://datasets/cpython/Doc/faq/programming.rst | unknown | edda7b58-bd69-4060-9295-d9036b4690eb | 1,692 | supabase-export-v2 | 187e0ccd4f38b7fb | def foo(mydict={}): # Danger: shared reference to one dict for all calls ... compute something ... mydict[key] = value return mydict
The first time you call this function, ``mydict`` contains a single item. The
second time, ``mydict`` contains two items because when ``foo()`` begins
executing, ``mydict`` starts out wit... | trusted_official_docs | CPython Docs | def foo(mydict={}): # Danger: shared reference to one dict for all calls ... compute something ... mydict[key] = value return mydict
The first time you call this function, ``mydict`` contains a single item. The
second time, ``mydict`` contains two items because when ``foo()`` begins
executing, ``mydict`` starts out wit... | def foo(mydict={}): # Danger: shared reference to one dict for all calls ... compute something ... mydict[key] = value return mydict
The first time you call this function, ``mydict`` contains a single item. The
second time, ``mydict`` contains two items because when ``foo()`` begins
executing, ``mydict`` starts out wit... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
bda0a5cd-51ce-4468-a2ae-0ca6702bf4bc | CPython Docs | file://datasets/cpython/Doc/faq/programming.rst | unknown | edda7b58-bd69-4060-9295-d9036b4690eb | 2,014 | supabase-export-v2 | bf0bbd741b84b894 | data, simply define a class attribute. To assign a new value to the attribute, you have to explicitly use the class name in the assignment::
class C:
count = 0 # number of times C.__init__ called | trusted_official_docs | CPython Docs | data, simply define a class attribute. To assign a new value to the attribute, you have to explicitly use the class name in the assignment::
class C:
count = 0 # number of times C.__init__ called | data, simply define a class attribute. To assign a new value to the attribute, you have to explicitly use the class name in the assignment::
class C:
count = 0 # number of times C.__init__ called | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
c14c8210-bd9a-40ce-9f45-f1fc37277c27 | CPython Docs | file://datasets/cpython/Doc/faq/programming.rst | unknown | edda7b58-bd69-4060-9295-d9036b4690eb | 1,911 | supabase-export-v2 | f42b0ad85ec2c552 | ["this", 1, "is", "an", "array"]
Lists are equivalent to C or Pascal arrays in their time complexity; the primary
difference is that a Python list can contain objects of many different types. | trusted_official_docs | CPython Docs | ["this", 1, "is", "an", "array"]
Lists are equivalent to C or Pascal arrays in their time complexity; the primary
difference is that a Python list can contain objects of many different types. | ["this", 1, "is", "an", "array"]
Lists are equivalent to C or Pascal arrays in their time complexity; the primary
difference is that a Python list can contain objects of many different types. | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
c18182d6-c59c-4781-901a-89bf1acb320a | CPython Docs | file://datasets/cpython/Doc/faq/programming.rst | unknown | edda7b58-bd69-4060-9295-d9036b4690eb | 1,893 | supabase-export-v2 | dbd07baf8980cf2e | convenient. For example ``S[:-1]`` is all of the string except for its last character, which is useful for removing the trailing newline from a string.
How do I iterate over a sequence in reverse order? -------------------------------------------------- | trusted_official_docs | CPython Docs | convenient. For example ``S[:-1]`` is all of the string except for its last character, which is useful for removing the trailing newline from a string.
How do I iterate over a sequence in reverse order? -------------------------------------------------- | convenient. For example ``S[:-1]`` is all of the string except for its last character, which is useful for removing the trailing newline from a string.
How do I iterate over a sequence in reverse order? -------------------------------------------------- | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
c22f8a03-7ad6-4bc2-8a30-5e82c1f82354 | CPython Docs | file://datasets/cpython/Doc/faq/programming.rst | unknown | edda7b58-bd69-4060-9295-d9036b4690eb | 1,650 | supabase-export-v2 | 15cc6a9aab1e7d87 | >>> foo() Traceback (most recent call last): ... UnboundLocalError: cannot access local variable 'x' where it is not associated with a value
This is because when you make an assignment to a variable in a scope, that
variable becomes local to that scope and shadows any similarly named variable
in the outer scope. Since ... | trusted_official_docs | CPython Docs | >>> foo() Traceback (most recent call last): ... UnboundLocalError: cannot access local variable 'x' where it is not associated with a value
This is because when you make an assignment to a variable in a scope, that
variable becomes local to that scope and shadows any similarly named variable
in the outer scope. Since ... | >>> foo() Traceback (most recent call last): ... UnboundLocalError: cannot access local variable 'x' where it is not associated with a value
This is because when you make an assignment to a variable in a scope, that
variable becomes local to that scope and shadows any similarly named variable
in the outer scope. Since ... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
c43d70e6-e4db-408a-ba4a-b97c29250647 | CPython Docs | file://datasets/cpython/Doc/faq/programming.rst | unknown | edda7b58-bd69-4060-9295-d9036b4690eb | 1,638 | supabase-export-v2 | e914a302e703d41c | `Nuitka <https://nuitka.net/>`_ (Cross-platform) * `PyInstaller <https://pyinstaller.org/>`_ (Cross-platform) * `PyOxidizer <https://pyoxidizer.readthedocs.io/en/stable/>`_ (Cross-platform) * `cx_Freeze <https://marcelotduarte.github.io/cx_Freeze/>`_ (Cross-platform) * `py2app <https://github.com/ronaldoussoren/py2app>... | trusted_official_docs | CPython Docs | `Nuitka <https://nuitka.net/>`_ (Cross-platform) * `PyInstaller <https://pyinstaller.org/>`_ (Cross-platform) * `PyOxidizer <https://pyoxidizer.readthedocs.io/en/stable/>`_ (Cross-platform) * `cx_Freeze <https://marcelotduarte.github.io/cx_Freeze/>`_ (Cross-platform) * `py2app <https://github.com/ronaldoussoren/py2app>... | `Nuitka <https://nuitka.net/>`_ (Cross-platform) * `PyInstaller <https://pyinstaller.org/>`_ (Cross-platform) * `PyOxidizer <https://pyoxidizer.readthedocs.io/en/stable/>`_ (Cross-platform) * `cx_Freeze <https://marcelotduarte.github.io/cx_Freeze/>`_ (Cross-platform) * `py2app <https://github.com/ronaldoussoren/py2app>... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
c5042e72-fcf9-484e-ad79-aade20b4f421 | CPython Docs | file://datasets/cpython/Doc/faq/programming.rst | unknown | edda7b58-bd69-4060-9295-d9036b4690eb | 2,095 | supabase-export-v2 | 9dd6294fa806234d | arguments. It does not create a reference to the instance. The cached method result will be kept only as long as the instance is alive.
The advantage is that when an instance is no longer used, the cached
method result will be released right away. The disadvantage is that if
instances accumulate, so too will the accumu... | trusted_official_docs | CPython Docs | arguments. It does not create a reference to the instance. The cached method result will be kept only as long as the instance is alive.
The advantage is that when an instance is no longer used, the cached
method result will be released right away. The disadvantage is that if
instances accumulate, so too will the accumu... | arguments. It does not create a reference to the instance. The cached method result will be kept only as long as the instance is alive.
The advantage is that when an instance is no longer used, the cached
method result will be released right away. The disadvantage is that if
instances accumulate, so too will the accumu... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
c6508074-b41c-41a7-b504-0dd0f55b003c | CPython Docs | file://datasets/cpython/Doc/faq/programming.rst | unknown | edda7b58-bd69-4060-9295-d9036b4690eb | 1,822 | supabase-export-v2 | 6d883a218706066d | as Python expressions, so that, for example, ``eval('09')`` gives a syntax error because Python does not allow leading '0' in a decimal number (except '0').
How do I convert a number to a string? -------------------------------------- | trusted_official_docs | CPython Docs | as Python expressions, so that, for example, ``eval('09')`` gives a syntax error because Python does not allow leading '0' in a decimal number (except '0').
How do I convert a number to a string? -------------------------------------- | as Python expressions, so that, for example, ``eval('09')`` gives a syntax error because Python does not allow leading '0' in a decimal number (except '0').
How do I convert a number to a string? -------------------------------------- | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
c6b7a434-5afd-4521-ac35-df08bfcf03e7 | CPython Docs | file://datasets/cpython/Doc/faq/programming.rst | unknown | edda7b58-bd69-4060-9295-d9036b4690eb | 1,889 | supabase-export-v2 | 2bb02722aac7657e | a copy but returns the same object, so it is cheap to call :func:`tuple` when you aren't sure that an object is already a tuple.
The type constructor ``list(seq)`` converts any sequence or iterable into a list
with the same items in the same order. For example, ``list((1, 2, 3))`` yields
``[1, 2, 3]`` and ``list('abc')... | trusted_official_docs | CPython Docs | a copy but returns the same object, so it is cheap to call :func:`tuple` when you aren't sure that an object is already a tuple.
The type constructor ``list(seq)`` converts any sequence or iterable into a list
with the same items in the same order. For example, ``list((1, 2, 3))`` yields
``[1, 2, 3]`` and ``list('abc')... | a copy but returns the same object, so it is cheap to call :func:`tuple` when you aren't sure that an object is already a tuple.
The type constructor ``list(seq)`` converts any sequence or iterable into a list
with the same items in the same order. For example, ``list((1, 2, 3))`` yields
``[1, 2, 3]`` and ``list('abc')... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
c6dc649b-cecd-4a21-b4dd-8cbf529de290 | CPython Docs | file://datasets/cpython/Doc/faq/programming.rst | unknown | edda7b58-bd69-4060-9295-d9036b4690eb | 1,953 | supabase-export-v2 | 405c08ce3aa3366f | >>> a_tuple[0] ['foo', 'item']
To see why this happens, you need to know that (a) if an object implements an
:meth:`~object.__iadd__` magic method, it gets called when the ``+=`` augmented
assignment
is executed, and its return value is what gets used in the assignment statement;
and (b) for lists, :meth:`!__iadd__` is... | trusted_official_docs | CPython Docs | >>> a_tuple[0] ['foo', 'item']
To see why this happens, you need to know that (a) if an object implements an
:meth:`~object.__iadd__` magic method, it gets called when the ``+=`` augmented
assignment
is executed, and its return value is what gets used in the assignment statement;
and (b) for lists, :meth:`!__iadd__` is... | >>> a_tuple[0] ['foo', 'item']
To see why this happens, you need to know that (a) if an object implements an
:meth:`~object.__iadd__` magic method, it gets called when the ``+=`` augmented
assignment
is executed, and its return value is what gets used in the assignment statement;
and (b) for lists, :meth:`!__iadd__` is... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
c981644d-8306-418d-9051-5853030c94bd | CPython Docs | file://datasets/cpython/Doc/faq/programming.rst | unknown | edda7b58-bd69-4060-9295-d9036b4690eb | 1,912 | supabase-export-v2 | ae2136fd0dc08bd4 | equivalent to C or Pascal arrays in their time complexity; the primary difference is that a Python list can contain objects of many different types.
The ``array`` module also provides methods for creating arrays of fixed types
with compact representations, but they are slower to index than lists. Also
note that `NumPy ... | trusted_official_docs | CPython Docs | equivalent to C or Pascal arrays in their time complexity; the primary difference is that a Python list can contain objects of many different types.
The ``array`` module also provides methods for creating arrays of fixed types
with compact representations, but they are slower to index than lists. Also
note that `NumPy ... | equivalent to C or Pascal arrays in their time complexity; the primary difference is that a Python list can contain objects of many different types.
The ``array`` module also provides methods for creating arrays of fixed types
with compact representations, but they are slower to index than lists. Also
note that `NumPy ... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
c98a691f-8192-45a5-8f37-2977903f9edf | CPython Docs | file://datasets/cpython/Doc/faq/programming.rst | unknown | edda7b58-bd69-4060-9295-d9036b4690eb | 1,643 | supabase-export-v2 | d1dcc3f42e21df0a | Why am I getting an UnboundLocalError when the variable has a value? --------------------------------------------------------------------
It can be a surprise to get the :exc:`UnboundLocalError` in previously working
code when it is modified by adding an assignment statement somewhere in
the body of a function. | trusted_official_docs | CPython Docs | Why am I getting an UnboundLocalError when the variable has a value? --------------------------------------------------------------------
It can be a surprise to get the :exc:`UnboundLocalError` in previously working
code when it is modified by adding an assignment statement somewhere in
the body of a function. | Why am I getting an UnboundLocalError when the variable has a value? --------------------------------------------------------------------
It can be a surprise to get the :exc:`UnboundLocalError` in previously working
code when it is modified by adding an assignment statement somewhere in
the body of a function. | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
cbfca5e4-caad-45f4-8f2c-3a60072ff759 | CPython Docs | file://datasets/cpython/Doc/faq/programming.rst | unknown | edda7b58-bd69-4060-9295-d9036b4690eb | 1,799 | supabase-export-v2 | f672a31ce99fe2cd | divmod(x, y, /) Return the tuple (x//y, x%y). Invariant: div*y + mod == x.
The slash at the end of the parameter list means that both parameters are
positional-only. Thus, calling :func:`divmod` with keyword arguments would lead
to an error:: | trusted_official_docs | CPython Docs | divmod(x, y, /) Return the tuple (x//y, x%y). Invariant: div*y + mod == x.
The slash at the end of the parameter list means that both parameters are
positional-only. Thus, calling :func:`divmod` with keyword arguments would lead
to an error:: | divmod(x, y, /) Return the tuple (x//y, x%y). Invariant: div*y + mod == x.
The slash at the end of the parameter list means that both parameters are
positional-only. Thus, calling :func:`divmod` with keyword arguments would lead
to an error:: | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
cc4b2d9d-49b4-4087-b70e-ee48703ee41f | CPython Docs | file://datasets/cpython/Doc/faq/programming.rst | unknown | edda7b58-bd69-4060-9295-d9036b4690eb | 2,052 | supabase-export-v2 | 3af4edf1100b39d4 | in that function's stack frame as contained in the stack trace. Normally, calling :func:`sys.exc_clear` will take care of this by clearing the last recorded exception.
Finally, if your :meth:`!__del__` method raises an exception, a warning message
is printed to :data:`sys.stderr`. | trusted_official_docs | CPython Docs | in that function's stack frame as contained in the stack trace. Normally, calling :func:`sys.exc_clear` will take care of this by clearing the last recorded exception.
Finally, if your :meth:`!__del__` method raises an exception, a warning message
is printed to :data:`sys.stderr`. | in that function's stack frame as contained in the stack trace. Normally, calling :func:`sys.exc_clear` will take care of this by clearing the last recorded exception.
Finally, if your :meth:`!__del__` method raises an exception, a warning message
is printed to :data:`sys.stderr`. | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
cc5490e8-4912-465a-bb61-fca035b4e713 | CPython Docs | file://datasets/cpython/Doc/faq/programming.rst | unknown | edda7b58-bd69-4060-9295-d9036b4690eb | 1,863 | supabase-export-v2 | ff524f8f8b5250f5 | >>> os.path.join(r'C:\this\will\work', '') 'C:\\this\\will\\work\\'
Note that while a backslash will "escape" a quote for the purposes of
determining where the raw string ends, no escaping occurs when interpreting the
value of the raw string. That is, the backslash remains present in the value of
the raw string:: | trusted_official_docs | CPython Docs | >>> os.path.join(r'C:\this\will\work', '') 'C:\\this\\will\\work\\'
Note that while a backslash will "escape" a quote for the purposes of
determining where the raw string ends, no escaping occurs when interpreting the
value of the raw string. That is, the backslash remains present in the value of
the raw string:: | >>> os.path.join(r'C:\this\will\work', '') 'C:\\this\\will\\work\\'
Note that while a backslash will "escape" a quote for the purposes of
determining where the raw string ends, no escaping occurs when interpreting the
value of the raw string. That is, the backslash remains present in the value of
the raw string:: | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
cd88cd81-5d3a-4eb1-ba5c-105a7c821cf7 | CPython Docs | file://datasets/cpython/Doc/faq/programming.rst | unknown | edda7b58-bd69-4060-9295-d9036b4690eb | 1,825 | supabase-export-v2 | 119014240f2fb760 | How do I modify a string in place? ----------------------------------
You can't, because strings are immutable. In most situations, you should
simply construct a new string from the various parts you want to assemble
it from. However, if you need an object with the ability to modify in-place
Unicode data, try using an ... | trusted_official_docs | CPython Docs | How do I modify a string in place? ----------------------------------
You can't, because strings are immutable. In most situations, you should
simply construct a new string from the various parts you want to assemble
it from. However, if you need an object with the ability to modify in-place
Unicode data, try using an ... | How do I modify a string in place? ----------------------------------
You can't, because strings are immutable. In most situations, you should
simply construct a new string from the various parts you want to assemble
it from. However, if you need an object with the ability to modify in-place
Unicode data, try using an ... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
ce23cc5e-a37f-4db2-a51c-af52fb8cdf43 | CPython Docs | file://datasets/cpython/Doc/faq/programming.rst | unknown | edda7b58-bd69-4060-9295-d9036b4690eb | 1,666 | supabase-export-v2 | 1e70711544e3b8cc | return ``4**2``, that is ``16``. You can also verify this by changing the value of ``x`` and see how the results of the lambdas change::
>>> x = 8
>>> squares[2]()
64 | trusted_official_docs | CPython Docs | return ``4**2``, that is ``16``. You can also verify this by changing the value of ``x`` and see how the results of the lambdas change::
>>> x = 8
>>> squares[2]()
64 | return ``4**2``, that is ``16``. You can also verify this by changing the value of ``x`` and see how the results of the lambdas change::
>>> x = 8
>>> squares[2]()
64 | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
cf2d796d-71f3-41e0-92a5-9f8fd9860837 | CPython Docs | file://datasets/cpython/Doc/faq/programming.rst | unknown | edda7b58-bd69-4060-9295-d9036b4690eb | 1,845 | supabase-export-v2 | 5b56ef2a9e3d9a9a | string ``S`` represents more than one line, with several empty lines at the end, the line terminators for all the blank lines will be removed::
>>> lines = ("line 1 \r\n"
... "\r\n"
... "\r\n")
>>> lines.rstrip("\n\r")
'line 1 ' | trusted_official_docs | CPython Docs | string ``S`` represents more than one line, with several empty lines at the end, the line terminators for all the blank lines will be removed::
>>> lines = ("line 1 \r\n"
... "\r\n"
... "\r\n")
>>> lines.rstrip("\n\r")
'line 1 ' | string ``S`` represents more than one line, with several empty lines at the end, the line terminators for all the blank lines will be removed::
>>> lines = ("line 1 \r\n"
... "\r\n"
... "\r\n")
>>> lines.rstrip("\n\r")
'line 1 ' | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
cf97ba9e-834e-4dc4-adfd-a00f6f7c08f1 | CPython Docs | file://datasets/cpython/Doc/faq/programming.rst | unknown | edda7b58-bd69-4060-9295-d9036b4690eb | 2,082 | supabase-export-v2 | 0ebf529cc1baa840 | def __contains__(self, value): for v in self: if v is value or v == value: return True return False
How can a subclass control what data is stored in an immutable instance? ------------------------------------------------------------------------ | trusted_official_docs | CPython Docs | def __contains__(self, value): for v in self: if v is value or v == value: return True return False
How can a subclass control what data is stored in an immutable instance? ------------------------------------------------------------------------ | def __contains__(self, value): for v in self: if v is value or v == value: return True return False
How can a subclass control what data is stored in an immutable instance? ------------------------------------------------------------------------ | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
cfeca28c-1311-4b13-94c4-f230c4a94074 | CPython Docs | file://datasets/cpython/Doc/faq/programming.rst | unknown | edda7b58-bd69-4060-9295-d9036b4690eb | 1,792 | supabase-export-v2 | 0450be812e41b4d6 | # First 10 Fibonacci numbers print(list(map(lambda x,f=lambda x,f:(f(x-1,f)+f(x-2,f)) if x>1 else 1: f(x,f), range(10))))
# Mandelbrot set
print((lambda Ru,Ro,Iu,Io,IM,Sx,Sy:reduce(lambda x,y:x+'\n'+y,map(lambda y,
Iu=Iu,Io=Io,Ru=Ru,Ro=Ro,Sy=Sy,L=lambda yc,Iu=Iu,Io=Io,Ru=Ru,Ro=Ro,i=IM,
Sx=Sx,Sy=Sy:reduce(lambda x,y:... | trusted_official_docs | CPython Docs | # First 10 Fibonacci numbers print(list(map(lambda x,f=lambda x,f:(f(x-1,f)+f(x-2,f)) if x>1 else 1: f(x,f), range(10))))
# Mandelbrot set
print((lambda Ru,Ro,Iu,Io,IM,Sx,Sy:reduce(lambda x,y:x+'\n'+y,map(lambda y,
Iu=Iu,Io=Io,Ru=Ru,Ro=Ro,Sy=Sy,L=lambda yc,Iu=Iu,Io=Io,Ru=Ru,Ro=Ro,i=IM,
Sx=Sx,Sy=Sy:reduce(lambda x,y:... | # First 10 Fibonacci numbers print(list(map(lambda x,f=lambda x,f:(f(x-1,f)+f(x-2,f)) if x>1 else 1: f(x,f), range(10))))
# Mandelbrot set
print((lambda Ru,Ro,Iu,Io,IM,Sx,Sy:reduce(lambda x,y:x+'\n'+y,map(lambda y,
Iu=Iu,Io=Io,Ru=Ru,Ro=Ro,Sy=Sy,L=lambda yc,Iu=Iu,Io=Io,Ru=Ru,Ro=Ro,i=IM,
Sx=Sx,Sy=Sy:reduce(lambda x,y:... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
d045c504-831d-4972-bfe0-d7a19e84b9c8 | CPython Docs | file://datasets/cpython/Doc/faq/programming.rst | unknown | edda7b58-bd69-4060-9295-d9036b4690eb | 1,948 | supabase-export-v2 | d4d5ebaf204b4276 | >>> result = a_tuple[0] + 1 >>> a_tuple[0] = result Traceback (most recent call last): ... TypeError: 'tuple' object does not support item assignment
It is the assignment part of the operation that produces the error, since a
tuple is immutable. | trusted_official_docs | CPython Docs | >>> result = a_tuple[0] + 1 >>> a_tuple[0] = result Traceback (most recent call last): ... TypeError: 'tuple' object does not support item assignment
It is the assignment part of the operation that produces the error, since a
tuple is immutable. | >>> result = a_tuple[0] + 1 >>> a_tuple[0] = result Traceback (most recent call last): ... TypeError: 'tuple' object does not support item assignment
It is the assignment part of the operation that produces the error, since a
tuple is immutable. | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
d0b94cb5-b0e2-43d8-8009-a3cd224dd709 | CPython Docs | file://datasets/cpython/Doc/faq/programming.rst | unknown | edda7b58-bd69-4060-9295-d9036b4690eb | 1,728 | supabase-export-v2 | fb20ddc9f1bc1d35 | you want to know if two variables refer to the same object or not, you can use the :keyword:`is` operator, or the built-in function :func:`id`.
How do I write a function with output parameters (call by reference)? --------------------------------------------------------------------- | trusted_official_docs | CPython Docs | you want to know if two variables refer to the same object or not, you can use the :keyword:`is` operator, or the built-in function :func:`id`.
How do I write a function with output parameters (call by reference)? --------------------------------------------------------------------- | you want to know if two variables refer to the same object or not, you can use the :keyword:`is` operator, or the built-in function :func:`id`.
How do I write a function with output parameters (call by reference)? --------------------------------------------------------------------- | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
d32b1d6d-dcca-4a15-8230-288825cba5d8 | CPython Docs | file://datasets/cpython/Doc/faq/programming.rst | unknown | edda7b58-bd69-4060-9295-d9036b4690eb | 1,767 | supabase-export-v2 | 8911f7155b632de4 | How can my code discover the name of an object? -----------------------------------------------
Generally speaking, it can't, because objects don't really have names. Essentially, assignment always binds a name to a value; the same is true of
``def`` and ``class`` statements, but in that case the value is a
callable. C... | trusted_official_docs | CPython Docs | How can my code discover the name of an object? -----------------------------------------------
Generally speaking, it can't, because objects don't really have names. Essentially, assignment always binds a name to a value; the same is true of
``def`` and ``class`` statements, but in that case the value is a
callable. C... | How can my code discover the name of an object? -----------------------------------------------
Generally speaking, it can't, because objects don't really have names. Essentially, assignment always binds a name to a value; the same is true of
``def`` and ``class`` statements, but in that case the value is a
callable. C... | python, official-docs, cpython, P0 | Local_Trusted_Corpus |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.