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
135918e5-fd05-4c79-8bdc-6e8f53a5c0b6
CPython Docs
file://datasets/cpython/Doc/faq/programming.rst
unknown
edda7b58-bd69-4060-9295-d9036b4690eb
2,056
supabase-export-v2
9ab5f5aeef70c3a6
Why does the result of ``id()`` appear to be not unique? -------------------------------------------------------- The :func:`id` builtin returns an integer that is guaranteed to be unique during the lifetime of the object. Since in CPython, this is the object's memory address, it happens frequently that after an object...
trusted_official_docs
CPython Docs
Why does the result of ``id()`` appear to be not unique? -------------------------------------------------------- The :func:`id` builtin returns an integer that is guaranteed to be unique during the lifetime of the object. Since in CPython, this is the object's memory address, it happens frequently that after an object...
Why does the result of ``id()`` appear to be not unique? -------------------------------------------------------- The :func:`id` builtin returns an integer that is guaranteed to be unique during the lifetime of the object. Since in CPython, this is the object's memory address, it happens frequently that after an object...
python, official-docs, cpython, P0
Local_Trusted_Corpus
13e531a6-64fd-4a5f-b141-4e36c7093220
CPython Docs
file://datasets/cpython/Doc/faq/programming.rst
unknown
edda7b58-bd69-4060-9295-d9036b4690eb
2,021
supabase-export-v2
209168f79c6e56ad
class C: @staticmethod def static(arg1, arg2, arg3): # No 'self' parameter! ... However, a far more straightforward way to get the effect of a static method is via a simple module-level function::
trusted_official_docs
CPython Docs
class C: @staticmethod def static(arg1, arg2, arg3): # No 'self' parameter! ... However, a far more straightforward way to get the effect of a static method is via a simple module-level function::
class C: @staticmethod def static(arg1, arg2, arg3): # No 'self' parameter! ... However, a far more straightforward way to get the effect of a static method is via a simple module-level function::
python, official-docs, cpython, P0
Local_Trusted_Corpus
1420a5c0-4be3-4607-ade6-9305a9cf1645
CPython Docs
file://datasets/cpython/Doc/faq/programming.rst
unknown
edda7b58-bd69-4060-9295-d9036b4690eb
1,969
supabase-export-v2
e9ae690be17fb645
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. A class can be based on one or more other classes, called its base class(es). It then inherits the attributes and methods of its base classes. This allows a...
trusted_official_docs
CPython Docs
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. A class can be based on one or more other classes, called its base class(es). It then inherits the attributes and methods of its base classes. This allows 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. A class can be based on one or more other classes, called its base class(es). It then inherits the attributes and methods of its base classes. This allows a...
python, official-docs, cpython, P0
Local_Trusted_Corpus
17388ece-0aa3-4399-b4fb-b7459bbe4162
CPython Docs
file://datasets/cpython/Doc/faq/programming.rst
unknown
edda7b58-bd69-4060-9295-d9036b4690eb
2,135
supabase-export-v2
63272d26e6368d04
The problem is that the interpreter will perform the following steps: * main imports ``foo`` * Empty globals for ``foo`` are created * ``foo`` is compiled and starts executing * ``foo`` imports ``bar`` * Empty globals for ``bar`` are created * ``bar`` is compiled and starts executing * ``bar`` imports ``foo`` (which is...
trusted_official_docs
CPython Docs
The problem is that the interpreter will perform the following steps: * main imports ``foo`` * Empty globals for ``foo`` are created * ``foo`` is compiled and starts executing * ``foo`` imports ``bar`` * Empty globals for ``bar`` are created * ``bar`` is compiled and starts executing * ``bar`` imports ``foo`` (which is...
The problem is that the interpreter will perform the following steps: * main imports ``foo`` * Empty globals for ``foo`` are created * ``foo`` is compiled and starts executing * ``foo`` imports ``bar`` * Empty globals for ``bar`` are created * ``bar`` is compiled and starts executing * ``bar`` imports ``foo`` (which is...
python, official-docs, cpython, P0
Local_Trusted_Corpus
174fe446-6aed-4193-b1ac-743ddb97ea65
CPython Docs
file://datasets/cpython/Doc/faq/programming.rst
unknown
edda7b58-bd69-4060-9295-d9036b4690eb
2,098
supabase-export-v2
a61e3c67bf911bc7
by the specified *maxsize*. The disadvantage is that instances are kept alive until they age out of the cache or until the cache is cleared. This example shows the various techniques::
trusted_official_docs
CPython Docs
by the specified *maxsize*. The disadvantage is that instances are kept alive until they age out of the cache or until the cache is cleared. This example shows the various techniques::
by the specified *maxsize*. The disadvantage is that instances are kept alive until they age out of the cache or until the cache is cleared. This example shows the various techniques::
python, official-docs, cpython, P0
Local_Trusted_Corpus
17b5e0d2-5c76-46a0-ab5a-e0b5276c988e
CPython Docs
file://datasets/cpython/Doc/faq/programming.rst
unknown
edda7b58-bd69-4060-9295-d9036b4690eb
1,695
supabase-export-v2
98aba4a534847e91
as numbers, strings, tuples, and ``None``, are safe from change. Changes to mutable objects such as dictionaries, lists, and class instances can lead to confusion. Because of this feature, it is good programming practice to not use mutable objects as default values. Instead, use ``None`` as the default value and inside...
trusted_official_docs
CPython Docs
as numbers, strings, tuples, and ``None``, are safe from change. Changes to mutable objects such as dictionaries, lists, and class instances can lead to confusion. Because of this feature, it is good programming practice to not use mutable objects as default values. Instead, use ``None`` as the default value and inside...
as numbers, strings, tuples, and ``None``, are safe from change. Changes to mutable objects such as dictionaries, lists, and class instances can lead to confusion. Because of this feature, it is good programming practice to not use mutable objects as default values. Instead, use ``None`` as the default value and inside...
python, official-docs, cpython, P0
Local_Trusted_Corpus
1898f97e-bf91-40c2-ae23-f57759dbb0f4
CPython Docs
file://datasets/cpython/Doc/faq/programming.rst
unknown
edda7b58-bd69-4060-9295-d9036b4690eb
1,656
supabase-export-v2
9216ba64a40ea21d
You can do a similar thing in a nested scope using the :keyword:`nonlocal` keyword: >>> def foo(): ... x = 10 ... def bar(): ... nonlocal x ... print(x) ... x += 1 ... bar() ... print(x) ... >>> foo() 10 11
trusted_official_docs
CPython Docs
You can do a similar thing in a nested scope using the :keyword:`nonlocal` keyword: >>> def foo(): ... x = 10 ... def bar(): ... nonlocal x ... print(x) ... x += 1 ... bar() ... print(x) ... >>> foo() 10 11
You can do a similar thing in a nested scope using the :keyword:`nonlocal` keyword: >>> def foo(): ... x = 10 ... def bar(): ... nonlocal x ... print(x) ... x += 1 ... bar() ... print(x) ... >>> foo() 10 11
python, official-docs, cpython, P0
Local_Trusted_Corpus
18e073ce-f5fc-483d-af79-57ea9d59ce70
CPython Docs
file://datasets/cpython/Doc/faq/programming.rst
unknown
edda7b58-bd69-4060-9295-d9036b4690eb
2,064
supabase-export-v2
5f82efd5ba9921c0
returns ``True``. Identity tests are usually faster than equality tests. And unlike equality tests, identity tests are guaranteed to return a boolean ``True`` or ``False``. However, identity tests can *only* be substituted for equality tests when object identity is assured. Generally, there are three circumstances wher...
trusted_official_docs
CPython Docs
returns ``True``. Identity tests are usually faster than equality tests. And unlike equality tests, identity tests are guaranteed to return a boolean ``True`` or ``False``. However, identity tests can *only* be substituted for equality tests when object identity is assured. Generally, there are three circumstances wher...
returns ``True``. Identity tests are usually faster than equality tests. And unlike equality tests, identity tests are guaranteed to return a boolean ``True`` or ``False``. However, identity tests can *only* be substituted for equality tests when object identity is assured. Generally, there are three circumstances wher...
python, official-docs, cpython, P0
Local_Trusted_Corpus
19aff06a-35d5-4c69-a64d-019456354661
CPython Docs
file://datasets/cpython/Doc/faq/programming.rst
unknown
edda7b58-bd69-4060-9295-d9036b4690eb
2,154
supabase-export-v2
4ff47660b0f44461
module contains class definitions, existing class instances will *not* be updated to use the new class definition. This can result in the following paradoxical behaviour:: >>> import importlib >>> import cls >>> c = cls.C() # Create an instance of C >>> importlib.reload(cls) <module 'cls' from 'cls.py'> >>> isinst...
trusted_official_docs
CPython Docs
module contains class definitions, existing class instances will *not* be updated to use the new class definition. This can result in the following paradoxical behaviour:: >>> import importlib >>> import cls >>> c = cls.C() # Create an instance of C >>> importlib.reload(cls) <module 'cls' from 'cls.py'> >>> isinst...
module contains class definitions, existing class instances will *not* be updated to use the new class definition. This can result in the following paradoxical behaviour:: >>> import importlib >>> import cls >>> c = cls.C() # Create an instance of C >>> importlib.reload(cls) <module 'cls' from 'cls.py'> >>> isinst...
python, official-docs, cpython, P0
Local_Trusted_Corpus
19be4f82-c241-4631-96e3-c1569326f59f
CPython Docs
file://datasets/cpython/Doc/faq/programming.rst
unknown
edda7b58-bd69-4060-9295-d9036b4690eb
2,137
supabase-export-v2
81f782900ca51039
The last step fails, because Python isn't done with interpreting ``foo`` yet and the global symbol dictionary for ``foo`` is still empty. The same thing happens when you use ``import foo``, and then try to access ``foo.foo_var`` in global code.
trusted_official_docs
CPython Docs
The last step fails, because Python isn't done with interpreting ``foo`` yet and the global symbol dictionary for ``foo`` is still empty. The same thing happens when you use ``import foo``, and then try to access ``foo.foo_var`` in global code.
The last step fails, because Python isn't done with interpreting ``foo`` yet and the global symbol dictionary for ``foo`` is still empty. The same thing happens when you use ``import foo``, and then try to access ``foo.foo_var`` in global code.
python, official-docs, cpython, P0
Local_Trusted_Corpus
1ae8edf6-928b-41de-b88b-242daaa5c18b
CPython Docs
file://datasets/cpython/Doc/faq/programming.rst
unknown
edda7b58-bd69-4060-9295-d9036b4690eb
2,089
supabase-export-v2
4eae50c649b30613
path" def __new__(cls, s): s = s.lower().replace(' ', '-') s = ''.join([c for c in s if c.isalnum() or c == '-']) return super().__new__(cls, s) The classes can be used like this:
trusted_official_docs
CPython Docs
path" def __new__(cls, s): s = s.lower().replace(' ', '-') s = ''.join([c for c in s if c.isalnum() or c == '-']) return super().__new__(cls, s) The classes can be used like this:
path" def __new__(cls, s): s = s.lower().replace(' ', '-') s = ''.join([c for c in s if c.isalnum() or c == '-']) return super().__new__(cls, s) The classes can be used like this:
python, official-docs, cpython, P0
Local_Trusted_Corpus
1c8301e0-11f7-4704-a305-a3712ed2b63d
CPython Docs
file://datasets/cpython/Doc/faq/programming.rst
unknown
edda7b58-bd69-4060-9295-d9036b4690eb
1,622
supabase-export-v2
599d08f4fca2490d
cool features such as debugging non-PythonWin programs. PythonWin is available as part of `pywin32 <https://github.com/mhammond/pywin32>`_ project and as a part of the `ActivePython <https://www.activestate.com/products/python/>`_ distribution. `Eric <https://eric-ide.python-projects.org/>`_ is an IDE built on PyQt and...
trusted_official_docs
CPython Docs
cool features such as debugging non-PythonWin programs. PythonWin is available as part of `pywin32 <https://github.com/mhammond/pywin32>`_ project and as a part of the `ActivePython <https://www.activestate.com/products/python/>`_ distribution. `Eric <https://eric-ide.python-projects.org/>`_ is an IDE built on PyQt and...
cool features such as debugging non-PythonWin programs. PythonWin is available as part of `pywin32 <https://github.com/mhammond/pywin32>`_ project and as a part of the `ActivePython <https://www.activestate.com/products/python/>`_ distribution. `Eric <https://eric-ide.python-projects.org/>`_ is an IDE built on PyQt and...
python, official-docs, cpython, P0
Local_Trusted_Corpus
1d29a6c0-b4d8-40d0-a398-4513f16ad16d
CPython Docs
file://datasets/cpython/Doc/faq/programming.rst
unknown
edda7b58-bd69-4060-9295-d9036b4690eb
1,664
supabase-export-v2
f6f7ad272875c6fb
when called, they would return, respectively, ``0``, ``1``, ``4``, ``9``, and ``16``. However, when you actually try you will see that they all return ``16``:: >>> squares[2]() 16 >>> squares[4]() 16
trusted_official_docs
CPython Docs
when called, they would return, respectively, ``0``, ``1``, ``4``, ``9``, and ``16``. However, when you actually try you will see that they all return ``16``:: >>> squares[2]() 16 >>> squares[4]() 16
when called, they would return, respectively, ``0``, ``1``, ``4``, ``9``, and ``16``. However, when you actually try you will see that they all return ``16``:: >>> squares[2]() 16 >>> squares[4]() 16
python, official-docs, cpython, P0
Local_Trusted_Corpus
2089051f-6b17-4c56-85b5-82513d3261e3
CPython Docs
file://datasets/cpython/Doc/faq/programming.rst
unknown
edda7b58-bd69-4060-9295-d9036b4690eb
1,768
supabase-export-v2
73df1a1e7f223462
to a value; the same is true of ``def`` and ``class`` statements, but in that case the value is a callable. Consider the following code:: >>> class A: ... pass ... >>> B = A >>> a = B() >>> b = a >>> print(b) <__main__.A object at 0x16D07CC> >>> print(a) <__main__.A object at 0x16D07CC>
trusted_official_docs
CPython Docs
to a value; the same is true of ``def`` and ``class`` statements, but in that case the value is a callable. Consider the following code:: >>> class A: ... pass ... >>> B = A >>> a = B() >>> b = a >>> print(b) <__main__.A object at 0x16D07CC> >>> print(a) <__main__.A object at 0x16D07CC>
to a value; the same is true of ``def`` and ``class`` statements, but in that case the value is a callable. Consider the following code:: >>> class A: ... pass ... >>> B = A >>> a = B() >>> b = a >>> print(b) <__main__.A object at 0x16D07CC> >>> print(a) <__main__.A object at 0x16D07CC>
python, official-docs, cpython, P0
Local_Trusted_Corpus
234a8790-a47e-4546-b5fc-f6a33c619270
CPython Docs
file://datasets/cpython/Doc/faq/programming.rst
unknown
edda7b58-bd69-4060-9295-d9036b4690eb
2,088
supabase-export-v2
dcc2bdc78564ccd6
NamedInt(int): "Allow text names for some numbers" xlat = {'zero': 0, 'one': 1, 'ten': 10} def __new__(cls, value): value = cls.xlat.get(value, value) return super().__new__(cls, value) class TitleStr(str): "Convert str to name suitable for a URL path" def __new__(cls, s): s = s.lower().replace(' ', '-') s = ''.joi...
trusted_official_docs
CPython Docs
NamedInt(int): "Allow text names for some numbers" xlat = {'zero': 0, 'one': 1, 'ten': 10} def __new__(cls, value): value = cls.xlat.get(value, value) return super().__new__(cls, value) class TitleStr(str): "Convert str to name suitable for a URL path" def __new__(cls, s): s = s.lower().replace(' ', '-') s = ''.joi...
NamedInt(int): "Allow text names for some numbers" xlat = {'zero': 0, 'one': 1, 'ten': 10} def __new__(cls, value): value = cls.xlat.get(value, value) return super().__new__(cls, value) class TitleStr(str): "Convert str to name suitable for a URL path" def __new__(cls, s): s = s.lower().replace(' ', '-') s = ''.joi...
python, official-docs, cpython, P0
Local_Trusted_Corpus
24410bbc-65a5-476a-b979-348128138aa8
CPython Docs
file://datasets/cpython/Doc/faq/programming.rst
unknown
edda7b58-bd69-4060-9295-d9036b4690eb
2,083
supabase-export-v2
df89fd453a77b42d
How can a subclass control what data is stored in an immutable instance? ------------------------------------------------------------------------ When subclassing an immutable type, override the :meth:`~object.__new__` method instead of the :meth:`~object.__init__` method. The latter only runs *after* an instance is cr...
trusted_official_docs
CPython Docs
How can a subclass control what data is stored in an immutable instance? ------------------------------------------------------------------------ When subclassing an immutable type, override the :meth:`~object.__new__` method instead of the :meth:`~object.__init__` method. The latter only runs *after* an instance is cr...
How can a subclass control what data is stored in an immutable instance? ------------------------------------------------------------------------ When subclassing an immutable type, override the :meth:`~object.__new__` method instead of the :meth:`~object.__init__` method. The latter only runs *after* an instance is cr...
python, official-docs, cpython, P0
Local_Trusted_Corpus
27034384-9d43-4322-b72c-9f3d7d5e6e0d
CPython Docs
file://datasets/cpython/Doc/faq/programming.rst
unknown
edda7b58-bd69-4060-9295-d9036b4690eb
2,048
supabase-export-v2
a7d7585818eb0300
:meth:`!__del__` methods are executed is arbitrary. You can run :func:`gc.collect` to force a collection, but there *are* pathological cases where objects will never be collected. Despite the cycle collector, it's still a good idea to define an explicit ``close()`` method on objects to be called whenever you're done wi...
trusted_official_docs
CPython Docs
:meth:`!__del__` methods are executed is arbitrary. You can run :func:`gc.collect` to force a collection, but there *are* pathological cases where objects will never be collected. Despite the cycle collector, it's still a good idea to define an explicit ``close()`` method on objects to be called whenever you're done wi...
:meth:`!__del__` methods are executed is arbitrary. You can run :func:`gc.collect` to force a collection, but there *are* pathological cases where objects will never be collected. Despite the cycle collector, it's still a good idea to define an explicit ``close()`` method on objects to be called whenever you're done wi...
python, official-docs, cpython, P0
Local_Trusted_Corpus
2721a4dd-2e3f-4c7b-ae55-93cac1b7ec29
CPython Docs
file://datasets/cpython/Doc/faq/programming.rst
unknown
edda7b58-bd69-4060-9295-d9036b4690eb
2,114
supabase-export-v2
d687413951a88c9d
How do I create a .pyc file? ---------------------------- When a module is imported for the first time (or when the source file has changed since the current compiled file was created) a ``.pyc`` file containing the compiled code should be created in a ``__pycache__`` subdirectory of the directory containing the ``.py`...
trusted_official_docs
CPython Docs
How do I create a .pyc file? ---------------------------- When a module is imported for the first time (or when the source file has changed since the current compiled file was created) a ``.pyc`` file containing the compiled code should be created in a ``__pycache__`` subdirectory of the directory containing the ``.py`...
How do I create a .pyc file? ---------------------------- When a module is imported for the first time (or when the source file has changed since the current compiled file was created) a ``.pyc`` file containing the compiled code should be created in a ``__pycache__`` subdirectory of the directory containing the ``.py`...
python, official-docs, cpython, P0
Local_Trusted_Corpus
2729e984-b35b-4f30-84d6-927b9773f4dd
CPython Docs
file://datasets/cpython/Doc/faq/programming.rst
unknown
edda7b58-bd69-4060-9295-d9036b4690eb
2,104
supabase-export-v2
850e59f4f09abb17
@lru_cache(maxsize=20) def historic_rainfall(self, date, units='mm'): "Rainfall on a given date" # Depends on the station_id, date, and units. The above example assumes that the *station_id* never changes. If the relevant instance attributes are mutable, the ``cached_property`` approach can't be made to work because it...
trusted_official_docs
CPython Docs
@lru_cache(maxsize=20) def historic_rainfall(self, date, units='mm'): "Rainfall on a given date" # Depends on the station_id, date, and units. The above example assumes that the *station_id* never changes. If the relevant instance attributes are mutable, the ``cached_property`` approach can't be made to work because it...
@lru_cache(maxsize=20) def historic_rainfall(self, date, units='mm'): "Rainfall on a given date" # Depends on the station_id, date, and units. The above example assumes that the *station_id* never changes. If the relevant instance attributes are mutable, the ``cached_property`` approach can't be made to work because it...
python, official-docs, cpython, P0
Local_Trusted_Corpus
2740091f-f278-4c3a-8b65-6513513be72e
CPython Docs
file://datasets/cpython/Doc/faq/programming.rst
unknown
edda7b58-bd69-4060-9295-d9036b4690eb
1,662
supabase-export-v2
9ff5a45d79806694
Assume you use a for loop to define a few different lambdas (or even plain functions), for example:: >>> squares = [] >>> for x in range(5): ... squares.append(lambda: x**2)
trusted_official_docs
CPython Docs
Assume you use a for loop to define a few different lambdas (or even plain functions), for example:: >>> squares = [] >>> for x in range(5): ... squares.append(lambda: x**2)
Assume you use a for loop to define a few different lambdas (or even plain functions), for example:: >>> squares = [] >>> for x in range(5): ... squares.append(lambda: x**2)
python, official-docs, cpython, P0
Local_Trusted_Corpus
27783e12-c348-4bd9-9465-7f1a8b2b6777
CPython Docs
file://datasets/cpython/Doc/faq/programming.rst
unknown
edda7b58-bd69-4060-9295-d9036b4690eb
2,122
supabase-export-v2
3da43dfb6c28f6f6
This will write the ``.pyc`` to a ``__pycache__`` subdirectory in the same location as ``foo.py`` (or you can override that with the optional parameter *cfile*). You can also automatically compile all files in a directory or directories using the :mod:`compileall` module. You can do it from the shell prompt by running ...
trusted_official_docs
CPython Docs
This will write the ``.pyc`` to a ``__pycache__`` subdirectory in the same location as ``foo.py`` (or you can override that with the optional parameter *cfile*). You can also automatically compile all files in a directory or directories using the :mod:`compileall` module. You can do it from the shell prompt by running ...
This will write the ``.pyc`` to a ``__pycache__`` subdirectory in the same location as ``foo.py`` (or you can override that with the optional parameter *cfile*). You can also automatically compile all files in a directory or directories using the :mod:`compileall` module. You can do it from the shell prompt by running ...
python, official-docs, cpython, P0
Local_Trusted_Corpus
28357513-51e4-4dff-9f96-b09b85afbea6
CPython Docs
file://datasets/cpython/Doc/faq/programming.rst
unknown
edda7b58-bd69-4060-9295-d9036b4690eb
2,105
supabase-export-v2
70fbc42f31f61935
never changes. If the relevant instance attributes are mutable, the ``cached_property`` approach can't be made to work because it cannot detect changes to the attributes. To make the ``lru_cache`` approach work when the *station_id* is mutable, the class needs to define the :meth:`~object.__eq__` and :meth:`~object.__h...
trusted_official_docs
CPython Docs
never changes. If the relevant instance attributes are mutable, the ``cached_property`` approach can't be made to work because it cannot detect changes to the attributes. To make the ``lru_cache`` approach work when the *station_id* is mutable, the class needs to define the :meth:`~object.__eq__` and :meth:`~object.__h...
never changes. If the relevant instance attributes are mutable, the ``cached_property`` approach can't be made to work because it cannot detect changes to the attributes. To make the ``lru_cache`` approach work when the *station_id* is mutable, the class needs to define the :meth:`~object.__eq__` and :meth:`~object.__h...
python, official-docs, cpython, P0
Local_Trusted_Corpus
2849ddbe-5196-4860-9bb0-2399dc72a404
CPython Docs
file://datasets/cpython/Doc/faq/programming.rst
unknown
edda7b58-bd69-4060-9295-d9036b4690eb
1,830
supabase-export-v2
807257ae431d264f
There are various techniques. * The best is to use a dictionary that maps strings to functions. The primary advantage of this technique is that the strings do not need to match the names of the functions. This is also the primary technique used to emulate a case construct::
trusted_official_docs
CPython Docs
There are various techniques. * The best is to use a dictionary that maps strings to functions. The primary advantage of this technique is that the strings do not need to match the names of the functions. This is also the primary technique used to emulate a case construct::
There are various techniques. * The best is to use a dictionary that maps strings to functions. The primary advantage of this technique is that the strings do not need to match the names of the functions. This is also the primary technique used to emulate a case construct::
python, official-docs, cpython, P0
Local_Trusted_Corpus
2b2921d5-4ced-46df-b475-81154617d12d
CPython Docs
file://datasets/cpython/Doc/faq/programming.rst
unknown
edda7b58-bd69-4060-9295-d9036b4690eb
2,066
supabase-export-v2
7f093d5dafcd4afa
1) Assignments create new names but do not change object identity. After the assignment ``new = old``, it is guaranteed that ``new is old``. 2) Putting an object in 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``.
trusted_official_docs
CPython Docs
1) Assignments create new names but do not change object identity. After the assignment ``new = old``, it is guaranteed that ``new is old``. 2) Putting an object in 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``.
1) Assignments create new names but do not change object identity. After the assignment ``new = old``, it is guaranteed that ``new is old``. 2) Putting an object in 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``.
python, official-docs, cpython, P0
Local_Trusted_Corpus
303966bc-c2d3-4ab3-8b0a-dddd4cc37657
CPython Docs
file://datasets/cpython/Doc/faq/programming.rst
unknown
edda7b58-bd69-4060-9295-d9036b4690eb
2,006
supabase-export-v2
27f865e823ed5258
class Derived(Base): def meth(self): super().meth() # calls Base.meth In the example, :func:`super` will automatically determine the instance from which it was called (the ``self`` value), look up the :term:`method resolution order` (MRO) with ``type(self).__mro__``, and return the next in line after ``Derived`` in the...
trusted_official_docs
CPython Docs
class Derived(Base): def meth(self): super().meth() # calls Base.meth In the example, :func:`super` will automatically determine the instance from which it was called (the ``self`` value), look up the :term:`method resolution order` (MRO) with ``type(self).__mro__``, and return the next in line after ``Derived`` in the...
class Derived(Base): def meth(self): super().meth() # calls Base.meth In the example, :func:`super` will automatically determine the instance from which it was called (the ``self`` value), look up the :term:`method resolution order` (MRO) with ``type(self).__mro__``, and return the next in line after ``Derived`` in the...
python, official-docs, cpython, P0
Local_Trusted_Corpus
305bc895-fdd1-40ad-8bb0-3bff4268a8ea
CPython Docs
file://datasets/cpython/Doc/faq/programming.rst
unknown
edda7b58-bd69-4060-9295-d9036b4690eb
2,069
supabase-export-v2
62ca7894a35f99a1
tests are preferred. In particular, identity tests should not be used to check constants such as :class:`int` and :class:`str` which aren't guaranteed to be singletons:: >>> a = 10_000_000 >>> b = 5_000_000 >>> c = b + 5_000_000 >>> a is c False
trusted_official_docs
CPython Docs
tests are preferred. In particular, identity tests should not be used to check constants such as :class:`int` and :class:`str` which aren't guaranteed to be singletons:: >>> a = 10_000_000 >>> b = 5_000_000 >>> c = b + 5_000_000 >>> a is c False
tests are preferred. In particular, identity tests should not be used to check constants such as :class:`int` and :class:`str` which aren't guaranteed to be singletons:: >>> a = 10_000_000 >>> b = 5_000_000 >>> c = b + 5_000_000 >>> a is c False
python, official-docs, cpython, P0
Local_Trusted_Corpus
30c2ba95-2233-4e58-bd67-705a33e68ef7
CPython Docs
file://datasets/cpython/Doc/faq/programming.rst
unknown
edda7b58-bd69-4060-9295-d9036b4690eb
1,735
supabase-export-v2
c841e6a27bfa84e7
3) By passing a mutable (changeable in-place) object:: >>> def func2(a): ... a[0] = 'new-value' # 'a' references a mutable list ... a[1] = a[1] + 1 # changes a shared object ... >>> args = ['old-value', 99] >>> func2(args) >>> args ['new-value', 100]
trusted_official_docs
CPython Docs
3) By passing a mutable (changeable in-place) object:: >>> def func2(a): ... a[0] = 'new-value' # 'a' references a mutable list ... a[1] = a[1] + 1 # changes a shared object ... >>> args = ['old-value', 99] >>> func2(args) >>> args ['new-value', 100]
3) By passing a mutable (changeable in-place) object:: >>> def func2(a): ... a[0] = 'new-value' # 'a' references a mutable list ... a[1] = a[1] + 1 # changes a shared object ... >>> args = ['old-value', 99] >>> func2(args) >>> args ['new-value', 100]
python, official-docs, cpython, P0
Local_Trusted_Corpus
31628aad-4f22-4621-8485-27282eb019f9
CPython Docs
file://datasets/cpython/Doc/faq/programming.rst
unknown
edda7b58-bd69-4060-9295-d9036b4690eb
1,872
supabase-export-v2
796ee37c930cfe16
* Making your algorithms faster (or changing to faster ones) can yield much larger benefits than trying to sprinkle micro-optimization tricks all over your code. * Use the right data structures. Study documentation for the :ref:`bltin-types` and the :mod:`collections` module.
trusted_official_docs
CPython Docs
* Making your algorithms faster (or changing to faster ones) can yield much larger benefits than trying to sprinkle micro-optimization tricks all over your code. * Use the right data structures. Study documentation for the :ref:`bltin-types` and the :mod:`collections` module.
* Making your algorithms faster (or changing to faster ones) can yield much larger benefits than trying to sprinkle micro-optimization tricks all over your code. * Use the right data structures. Study documentation for the :ref:`bltin-types` and the :mod:`collections` module.
python, official-docs, cpython, P0
Local_Trusted_Corpus
32064eac-d109-47f2-a41a-3fe24da1ec21
CPython Docs
file://datasets/cpython/Doc/faq/programming.rst
unknown
edda7b58-bd69-4060-9295-d9036b4690eb
2,018
supabase-export-v2
cdcfccf592194558
``c`` such that ``isinstance(c, C)`` holds, unless overridden by ``c`` itself or by some class on the base-class search path from ``c.__class__`` back to ``C``. Caution: within a method of C, an assignment like ``self.count = 42`` creates a new and unrelated instance named "count" in ``self``'s own dict. Rebinding of a...
trusted_official_docs
CPython Docs
``c`` such that ``isinstance(c, C)`` holds, unless overridden by ``c`` itself or by some class on the base-class search path from ``c.__class__`` back to ``C``. Caution: within a method of C, an assignment like ``self.count = 42`` creates a new and unrelated instance named "count" in ``self``'s own dict. Rebinding of a...
``c`` such that ``isinstance(c, C)`` holds, unless overridden by ``c`` itself or by some class on the base-class search path from ``c.__class__`` back to ``C``. Caution: within a method of C, an assignment like ``self.count = 42`` creates a new and unrelated instance named "count" in ``self``'s own dict. Rebinding of a...
python, official-docs, cpython, P0
Local_Trusted_Corpus
337b3b3c-ec11-4431-ad57-d6b4639ce55d
CPython Docs
file://datasets/cpython/Doc/faq/programming.rst
unknown
edda7b58-bd69-4060-9295-d9036b4690eb
1,945
supabase-export-v2
44d743489da29fb7
>>> a_tuple = (1, 2) >>> a_tuple[0] += 1 Traceback (most recent call last): ... TypeError: 'tuple' object does not support item assignment The reason for the exception should be immediately clear: ``1`` is added to the object ``a_tuple[0]`` points to (``1``), producing the result object, ``2``, but when we attempt to a...
trusted_official_docs
CPython Docs
>>> a_tuple = (1, 2) >>> a_tuple[0] += 1 Traceback (most recent call last): ... TypeError: 'tuple' object does not support item assignment The reason for the exception should be immediately clear: ``1`` is added to the object ``a_tuple[0]`` points to (``1``), producing the result object, ``2``, but when we attempt to a...
>>> a_tuple = (1, 2) >>> a_tuple[0] += 1 Traceback (most recent call last): ... TypeError: 'tuple' object does not support item assignment The reason for the exception should be immediately clear: ``1`` is added to the object ``a_tuple[0]`` points to (``1``), producing the result object, ``2``, but when we attempt to a...
python, official-docs, cpython, P0
Local_Trusted_Corpus
3412deae-865c-41e2-846f-3987edab654f
CPython Docs
file://datasets/cpython/Doc/faq/programming.rst
unknown
edda7b58-bd69-4060-9295-d9036b4690eb
2,062
supabase-export-v2
fa3f428c26eae4a9
When can I rely on identity tests with the *is* operator? --------------------------------------------------------- The ``is`` operator tests for object identity. The test ``a is b`` is equivalent to ``id(a) == id(b)``.
trusted_official_docs
CPython Docs
When can I rely on identity tests with the *is* operator? --------------------------------------------------------- The ``is`` operator tests for object identity. The test ``a is b`` is equivalent to ``id(a) == id(b)``.
When can I rely on identity tests with the *is* operator? --------------------------------------------------------- The ``is`` operator tests for object identity. The test ``a is b`` is equivalent to ``id(a) == id(b)``.
python, official-docs, cpython, P0
Local_Trusted_Corpus
3495c72d-b24f-46ff-ad55-5ba757ef22ef
CPython Docs
file://datasets/cpython/Doc/faq/programming.rst
unknown
edda7b58-bd69-4060-9295-d9036b4690eb
1,846
supabase-export-v2
c2164d7509f30f84
>>> lines = ("line 1 \r\n" ... "\r\n" ... "\r\n") >>> lines.rstrip("\n\r") 'line 1 ' Since this is typically only desired when reading text one line at a time, using ``S.rstrip()`` this way works well.
trusted_official_docs
CPython Docs
>>> lines = ("line 1 \r\n" ... "\r\n" ... "\r\n") >>> lines.rstrip("\n\r") 'line 1 ' Since this is typically only desired when reading text one line at a time, using ``S.rstrip()`` this way works well.
>>> lines = ("line 1 \r\n" ... "\r\n" ... "\r\n") >>> lines.rstrip("\n\r") 'line 1 ' Since this is typically only desired when reading text one line at a time, using ``S.rstrip()`` this way works well.
python, official-docs, cpython, P0
Local_Trusted_Corpus
34a00635-3748-46bb-9455-1091896e934a
CPython Docs
file://datasets/cpython/Doc/faq/programming.rst
unknown
edda7b58-bd69-4060-9295-d9036b4690eb
1,941
supabase-export-v2
9897ef72fc551b81
Why does a_tuple[i] += ['item'] raise an exception when the addition works? --------------------------------------------------------------------------- This is because of a combination of the fact that augmented assignment operators are *assignment* operators, and the difference between mutable and immutable objects in...
trusted_official_docs
CPython Docs
Why does a_tuple[i] += ['item'] raise an exception when the addition works? --------------------------------------------------------------------------- This is because of a combination of the fact that augmented assignment operators are *assignment* operators, and the difference between mutable and immutable objects in...
Why does a_tuple[i] += ['item'] raise an exception when the addition works? --------------------------------------------------------------------------- This is because of a combination of the fact that augmented assignment operators are *assignment* operators, and the difference between mutable and immutable objects in...
python, official-docs, cpython, P0
Local_Trusted_Corpus
395096f9-49a8-4432-951e-cc2527ed1baa
CPython Docs
file://datasets/cpython/Doc/faq/programming.rst
unknown
edda7b58-bd69-4060-9295-d9036b4690eb
1,942
supabase-export-v2
fc929e79ea514c5c
is because of a combination of the fact that augmented assignment operators are *assignment* operators, and the difference between mutable and immutable objects in Python. This discussion applies in general when augmented assignment operators are applied to elements of a tuple that point to mutable objects, but we'll u...
trusted_official_docs
CPython Docs
is because of a combination of the fact that augmented assignment operators are *assignment* operators, and the difference between mutable and immutable objects in Python. This discussion applies in general when augmented assignment operators are applied to elements of a tuple that point to mutable objects, but we'll u...
is because of a combination of the fact that augmented assignment operators are *assignment* operators, and the difference between mutable and immutable objects in Python. This discussion applies in general when augmented assignment operators are applied to elements of a tuple that point to mutable objects, but we'll u...
python, official-docs, cpython, P0
Local_Trusted_Corpus
3b5a2f4f-385c-4d79-a79d-bd59bd935b71
CPython Docs
file://datasets/cpython/Doc/faq/programming.rst
unknown
edda7b58-bd69-4060-9295-d9036b4690eb
1,871
supabase-export-v2
779647f3da46b1d0
said, there are many tricks to speed up Python code. Here are some general principles which go a long way towards reaching acceptable performance levels: * Making your algorithms faster (or changing to faster ones) can yield much larger benefits than trying to sprinkle micro-optimization tricks all over your code.
trusted_official_docs
CPython Docs
said, there are many tricks to speed up Python code. Here are some general principles which go a long way towards reaching acceptable performance levels: * Making your algorithms faster (or changing to faster ones) can yield much larger benefits than trying to sprinkle micro-optimization tricks all over your code.
said, there are many tricks to speed up Python code. Here are some general principles which go a long way towards reaching acceptable performance levels: * Making your algorithms faster (or changing to faster ones) can yield much larger benefits than trying to sprinkle micro-optimization tricks all over your code.
python, official-docs, cpython, P0
Local_Trusted_Corpus
3b8d4f07-86a1-448b-b839-23551c22f601
CPython Docs
file://datasets/cpython/Doc/faq/programming.rst
unknown
edda7b58-bd69-4060-9295-d9036b4690eb
2,096
supabase-export-v2
70b2e4209452537e
result will be released right away. The disadvantage is that if instances accumulate, so too will the accumulated method results. They can grow without bound. The ``lru_cache`` approach works with methods that have :term:`hashable` arguments. It creates a reference to the instance unless special efforts are made to pas...
trusted_official_docs
CPython Docs
result will be released right away. The disadvantage is that if instances accumulate, so too will the accumulated method results. They can grow without bound. The ``lru_cache`` approach works with methods that have :term:`hashable` arguments. It creates a reference to the instance unless special efforts are made to pas...
result will be released right away. The disadvantage is that if instances accumulate, so too will the accumulated method results. They can grow without bound. The ``lru_cache`` approach works with methods that have :term:`hashable` arguments. It creates a reference to the instance unless special efforts are made to pas...
python, official-docs, cpython, P0
Local_Trusted_Corpus
3c39b782-956d-457e-88b5-1df8dc226bb1
CPython Docs
file://datasets/cpython/Doc/faq/programming.rst
unknown
edda7b58-bd69-4060-9295-d9036b4690eb
2,007
supabase-export-v2
8b558821e85b1ff8
called (the ``self`` value), look up the :term:`method resolution order` (MRO) with ``type(self).__mro__``, and return the next in line after ``Derived`` in the MRO: ``Base``. How can I organize my code to make it easier to change the base class? ----------------------------------------------------------------------
trusted_official_docs
CPython Docs
called (the ``self`` value), look up the :term:`method resolution order` (MRO) with ``type(self).__mro__``, and return the next in line after ``Derived`` in the MRO: ``Base``. How can I organize my code to make it easier to change the base class? ----------------------------------------------------------------------
called (the ``self`` value), look up the :term:`method resolution order` (MRO) with ``type(self).__mro__``, and return the next in line after ``Derived`` in the MRO: ``Base``. How can I organize my code to make it easier to change the base class? ----------------------------------------------------------------------
python, official-docs, cpython, P0
Local_Trusted_Corpus
3cf2375b-74f8-4275-92c4-e5c794326279
CPython Docs
file://datasets/cpython/Doc/faq/programming.rst
unknown
edda7b58-bd69-4060-9295-d9036b4690eb
2,140
supabase-export-v2
84a3a3ab8352780a
Initializations of global variables and class variables should use constants or built-in functions only. This means everything from an imported module is referenced as ``<module>.<name>``. Jim Roskind suggests performing steps in the following order in each module:
trusted_official_docs
CPython Docs
Initializations of global variables and class variables should use constants or built-in functions only. This means everything from an imported module is referenced as ``<module>.<name>``. Jim Roskind suggests performing steps in the following order in each module:
Initializations of global variables and class variables should use constants or built-in functions only. This means everything from an imported module is referenced as ``<module>.<name>``. Jim Roskind suggests performing steps in the following order in each module:
python, official-docs, cpython, P0
Local_Trusted_Corpus
3dc783c1-bd28-4fe8-a4e9-bb27cee5b8eb
CPython Docs
file://datasets/cpython/Doc/faq/programming.rst
unknown
edda7b58-bd69-4060-9295-d9036b4690eb
1,667
supabase-export-v2
e8ba14fcd5543fc8
>>> x = 8 >>> squares[2]() 64 In order to avoid this, you need to save the values in variables local to the lambdas, so that they don't rely on the value of the global ``x``::
trusted_official_docs
CPython Docs
>>> x = 8 >>> squares[2]() 64 In order to avoid this, you need to save the values in variables local to the lambdas, so that they don't rely on the value of the global ``x``::
>>> x = 8 >>> squares[2]() 64 In order to avoid this, you need to save the values in variables local to the lambdas, so that they don't rely on the value of the global ``x``::
python, official-docs, cpython, P0
Local_Trusted_Corpus
3e7ac74b-777c-424c-825b-a214f7cde25e
CPython Docs
file://datasets/cpython/Doc/faq/programming.rst
unknown
edda7b58-bd69-4060-9295-d9036b4690eb
1,887
supabase-export-v2
1be2a6600141cfc2
How do I convert between tuples and lists? ------------------------------------------ The type constructor ``tuple(seq)`` converts any sequence (actually, any iterable) into a tuple with the same items in the same order.
trusted_official_docs
CPython Docs
How do I convert between tuples and lists? ------------------------------------------ The type constructor ``tuple(seq)`` converts any sequence (actually, any iterable) into a tuple with the same items in the same order.
How do I convert between tuples and lists? ------------------------------------------ The type constructor ``tuple(seq)`` converts any sequence (actually, any iterable) into a tuple with the same items in the same order.
python, official-docs, cpython, P0
Local_Trusted_Corpus
3fe7f41e-93c5-4053-8963-69c63637dfe8
CPython Docs
file://datasets/cpython/Doc/faq/programming.rst
unknown
edda7b58-bd69-4060-9295-d9036b4690eb
1,966
supabase-export-v2
e35d409efd84e508
Merge them into an iterator of tuples, sort the resulting list, and then pick out the element you want. >>> list1 = ["what", "I'm", "sorting", "by"] >>> list2 = ["something", "else", "to", "sort"] >>> pairs = zip(list1, list2) >>> pairs = sorted(pairs) >>> pairs [("I'm", 'else'), ('by', 'sort'), ('sorting', 'to'),...
trusted_official_docs
CPython Docs
Merge them into an iterator of tuples, sort the resulting list, and then pick out the element you want. >>> list1 = ["what", "I'm", "sorting", "by"] >>> list2 = ["something", "else", "to", "sort"] >>> pairs = zip(list1, list2) >>> pairs = sorted(pairs) >>> pairs [("I'm", 'else'), ('by', 'sort'), ('sorting', 'to'),...
Merge them into an iterator of tuples, sort the resulting list, and then pick out the element you want. >>> list1 = ["what", "I'm", "sorting", "by"] >>> list2 = ["something", "else", "to", "sort"] >>> pairs = zip(list1, list2) >>> pairs = sorted(pairs) >>> pairs [("I'm", 'else'), ('by', 'sort'), ('sorting', 'to'),...
python, official-docs, cpython, P0
Local_Trusted_Corpus
417b3cce-057e-4a68-9eb2-97f9fa007993
CPython Docs
file://datasets/cpython/Doc/faq/programming.rst
unknown
edda7b58-bd69-4060-9295-d9036b4690eb
1,770
supabase-export-v2
1ad7e77430cef32f
class ``A``. However, it is impossible to say whether the instance's name is ``a`` or ``b``, since both names are bound to the same value. Generally speaking it should not be necessary for your code to "know the names" of particular values. Unless you are deliberately writing introspective programs, this is usually an ...
trusted_official_docs
CPython Docs
class ``A``. However, it is impossible to say whether the instance's name is ``a`` or ``b``, since both names are bound to the same value. Generally speaking it should not be necessary for your code to "know the names" of particular values. Unless you are deliberately writing introspective programs, this is usually an ...
class ``A``. However, it is impossible to say whether the instance's name is ``a`` or ``b``, since both names are bound to the same value. Generally speaking it should not be necessary for your code to "know the names" of particular values. Unless you are deliberately writing introspective programs, this is usually an ...
python, official-docs, cpython, P0
Local_Trusted_Corpus
41839ff5-480c-4fbb-ba6b-746f0240821e
CPython Docs
file://datasets/cpython/Doc/faq/programming.rst
unknown
edda7b58-bd69-4060-9295-d9036b4690eb
1,766
supabase-export-v2
fe8b45bf5bccea31
of a user-defined class, :func:`dir(x) <dir>` returns an alphabetized list of the names containing the instance attributes and methods and attributes defined by its class. How can my code discover the name of an object? -----------------------------------------------
trusted_official_docs
CPython Docs
of a user-defined class, :func:`dir(x) <dir>` returns an alphabetized list of the names containing the instance attributes and methods and attributes defined by its class. How can my code discover the name of an object? -----------------------------------------------
of a user-defined class, :func:`dir(x) <dir>` returns an alphabetized list of the names containing the instance attributes and methods and attributes defined by its class. How can my code discover the name of an object? -----------------------------------------------
python, official-docs, cpython, P0
Local_Trusted_Corpus
41ce080a-8209-42f2-a097-9898299207df
CPython Docs
file://datasets/cpython/Doc/faq/programming.rst
unknown
edda7b58-bd69-4060-9295-d9036b4690eb
1,888
supabase-export-v2
b730d26f333393a3
The type constructor ``tuple(seq)`` converts any sequence (actually, any iterable) into a tuple with the same items in the same order. For example, ``tuple([1, 2, 3])`` yields ``(1, 2, 3)`` and ``tuple('abc')`` yields ``('a', 'b', 'c')``. If the argument is a tuple, it does not make a copy but returns the same object, ...
trusted_official_docs
CPython Docs
The type constructor ``tuple(seq)`` converts any sequence (actually, any iterable) into a tuple with the same items in the same order. For example, ``tuple([1, 2, 3])`` yields ``(1, 2, 3)`` and ``tuple('abc')`` yields ``('a', 'b', 'c')``. If the argument is a tuple, it does not make a copy but returns the same object, ...
The type constructor ``tuple(seq)`` converts any sequence (actually, any iterable) into a tuple with the same items in the same order. For example, ``tuple([1, 2, 3])`` yields ``(1, 2, 3)`` and ``tuple('abc')`` yields ``('a', 'b', 'c')``. If the argument is a tuple, it does not make a copy but returns the same object, ...
python, official-docs, cpython, P0
Local_Trusted_Corpus
42d6685d-cd48-4902-ad49-4f0e1091330c
CPython Docs
file://datasets/cpython/Doc/faq/programming.rst
unknown
edda7b58-bd69-4060-9295-d9036b4690eb
1,659
supabase-export-v2
f2444090a4a244a3
implicitly global. If a variable is assigned a value anywhere within the function's body, it's assumed to be a local unless explicitly declared as global. Though a bit surprising at first, a moment's consideration explains this. On one hand, requiring :keyword:`global` for assigned variables provides a bar against unin...
trusted_official_docs
CPython Docs
implicitly global. If a variable is assigned a value anywhere within the function's body, it's assumed to be a local unless explicitly declared as global. Though a bit surprising at first, a moment's consideration explains this. On one hand, requiring :keyword:`global` for assigned variables provides a bar against unin...
implicitly global. If a variable is assigned a value anywhere within the function's body, it's assumed to be a local unless explicitly declared as global. Though a bit surprising at first, a moment's consideration explains this. On one hand, requiring :keyword:`global` for assigned variables provides a bar against unin...
python, official-docs, cpython, P0
Local_Trusted_Corpus
44cc3b1c-1443-4b1b-9e12-fcfc9351db81
CPython Docs
file://datasets/cpython/Doc/faq/programming.rst
unknown
edda7b58-bd69-4060-9295-d9036b4690eb
1,959
supabase-export-v2
b2f2decc352b6d2f
Thus, in our tuple example what is happening is equivalent to:: >>> result = a_tuple[0].__iadd__(['item']) >>> a_tuple[0] = result Traceback (most recent call last): ... TypeError: 'tuple' object does not support item assignment
trusted_official_docs
CPython Docs
Thus, in our tuple example what is happening is equivalent to:: >>> result = a_tuple[0].__iadd__(['item']) >>> a_tuple[0] = result Traceback (most recent call last): ... TypeError: 'tuple' object does not support item assignment
Thus, in our tuple example what is happening is equivalent to:: >>> result = a_tuple[0].__iadd__(['item']) >>> 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
454f39ad-a0af-487e-9d52-c57d5efdb945
CPython Docs
file://datasets/cpython/Doc/faq/programming.rst
unknown
edda7b58-bd69-4060-9295-d9036b4690eb
1,665
supabase-export-v2
70a1c0b449482c95
>>> squares[2]() 16 >>> squares[4]() 16 This happens because ``x`` is not local to the lambdas, but is defined in the outer scope, and it is accessed when the lambda is called --- not when it is defined. At the end of the loop, the value of ``x`` is ``4``, so all the functions now return ``4**2``, that is ``16``. You c...
trusted_official_docs
CPython Docs
>>> squares[2]() 16 >>> squares[4]() 16 This happens because ``x`` is not local to the lambdas, but is defined in the outer scope, and it is accessed when the lambda is called --- not when it is defined. At the end of the loop, the value of ``x`` is ``4``, so all the functions now return ``4**2``, that is ``16``. You c...
>>> squares[2]() 16 >>> squares[4]() 16 This happens because ``x`` is not local to the lambdas, but is defined in the outer scope, and it is accessed when the lambda is called --- not when it is defined. At the end of the loop, the value of ``x`` is ``4``, so all the functions now return ``4**2``, that is ``16``. You c...
python, official-docs, cpython, P0
Local_Trusted_Corpus
47158885-ace7-4d9f-bfc8-48e1d4ea8ec9
CPython Docs
file://datasets/cpython/Doc/faq/programming.rst
unknown
edda7b58-bd69-4060-9295-d9036b4690eb
1,844
supabase-export-v2
03be3a373cb236ca
Is there an equivalent to Perl's ``chomp()`` for removing trailing newlines from strings? ----------------------------------------------------------------------------------------- You can use ``S.rstrip("\r\n")`` to remove all occurrences of any line terminator from the end of the string ``S`` without removing other tr...
trusted_official_docs
CPython Docs
Is there an equivalent to Perl's ``chomp()`` for removing trailing newlines from strings? ----------------------------------------------------------------------------------------- You can use ``S.rstrip("\r\n")`` to remove all occurrences of any line terminator from the end of the string ``S`` without removing other tr...
Is there an equivalent to Perl's ``chomp()`` for removing trailing newlines from strings? ----------------------------------------------------------------------------------------- You can use ``S.rstrip("\r\n")`` to remove all occurrences of any line terminator from the end of the string ``S`` without removing other tr...
python, official-docs, cpython, P0
Local_Trusted_Corpus
489e9f50-f06f-4aaa-9867-2ddb244abc79
CPython Docs
file://datasets/cpython/Doc/faq/programming.rst
unknown
edda7b58-bd69-4060-9295-d9036b4690eb
1,732
supabase-export-v2
7fc4d30bdf5246fb
# assigned to new objects ... return a, b # return new values ... >>> x, y = 'old-value', 99 >>> func1(x, y) ('new-value', 100) This is almost always the clearest solution.
trusted_official_docs
CPython Docs
# assigned to new objects ... return a, b # return new values ... >>> x, y = 'old-value', 99 >>> func1(x, y) ('new-value', 100) This is almost always the clearest solution.
# assigned to new objects ... return a, b # return new values ... >>> x, y = 'old-value', 99 >>> func1(x, y) ('new-value', 100) This is almost always the clearest solution.
python, official-docs, cpython, P0
Local_Trusted_Corpus
49896be7-2d52-4870-9119-0c9a3c3141ab
CPython Docs
file://datasets/cpython/Doc/faq/programming.rst
unknown
edda7b58-bd69-4060-9295-d9036b4690eb
1,913
supabase-export-v2
fb038dd7bd661f14
but they are slower to index than lists. Also note that `NumPy <https://numpy.org/>`_ and other third-party packages define array-like structures with various characteristics as well. To get Lisp-style linked lists, you can emulate *cons cells* using tuples::
trusted_official_docs
CPython Docs
but they are slower to index than lists. Also note that `NumPy <https://numpy.org/>`_ and other third-party packages define array-like structures with various characteristics as well. To get Lisp-style linked lists, you can emulate *cons cells* using tuples::
but they are slower to index than lists. Also note that `NumPy <https://numpy.org/>`_ and other third-party packages define array-like structures with various characteristics as well. To get Lisp-style linked lists, you can emulate *cons cells* using tuples::
python, official-docs, cpython, P0
Local_Trusted_Corpus
49f15400-0f5c-4005-8961-d99661a57128
CPython Docs
file://datasets/cpython/Doc/faq/programming.rst
unknown
edda7b58-bd69-4060-9295-d9036b4690eb
2,118
supabase-export-v2
a59c83f8a4d5c462
a ``.pyc`` will be created for ``xyz`` because ``xyz`` is imported, but no ``.pyc`` file will be created for ``foo`` since ``foo.py`` isn't being imported. If you need to create a ``.pyc`` file for ``foo`` -- that is, to create a ``.pyc`` file for a module that is not imported -- you can, using the :mod:`py_compile` an...
trusted_official_docs
CPython Docs
a ``.pyc`` will be created for ``xyz`` because ``xyz`` is imported, but no ``.pyc`` file will be created for ``foo`` since ``foo.py`` isn't being imported. If you need to create a ``.pyc`` file for ``foo`` -- that is, to create a ``.pyc`` file for a module that is not imported -- you can, using the :mod:`py_compile` an...
a ``.pyc`` will be created for ``xyz`` because ``xyz`` is imported, but no ``.pyc`` file will be created for ``foo`` since ``foo.py`` isn't being imported. If you need to create a ``.pyc`` file for ``foo`` -- that is, to create a ``.pyc`` file for a module that is not imported -- you can, using the :mod:`py_compile` an...
python, official-docs, cpython, P0
Local_Trusted_Corpus
49f5d409-cc08-4d7b-9cad-deaad4de8bc7
CPython Docs
file://datasets/cpython/Doc/faq/programming.rst
unknown
edda7b58-bd69-4060-9295-d9036b4690eb
2,063
supabase-export-v2
f7e8ead5f948706e
The ``is`` operator tests for object identity. The test ``a is b`` is equivalent to ``id(a) == id(b)``. The most important property of an identity test is that an object is always identical to itself, ``a is a`` always returns ``True``. Identity tests are usually faster than equality tests. And unlike equality tests, i...
trusted_official_docs
CPython Docs
The ``is`` operator tests for object identity. The test ``a is b`` is equivalent to ``id(a) == id(b)``. The most important property of an identity test is that an object is always identical to itself, ``a is a`` always returns ``True``. Identity tests are usually faster than equality tests. And unlike equality tests, i...
The ``is`` operator tests for object identity. The test ``a is b`` is equivalent to ``id(a) == id(b)``. The most important property of an identity test is that an object is always identical to itself, ``a is a`` always returns ``True``. Identity tests are usually faster than equality tests. And unlike equality tests, i...
python, official-docs, cpython, P0
Local_Trusted_Corpus
4a15e3d5-98b9-4316-8a48-8557aa55471c
CPython Docs
file://datasets/cpython/Doc/faq/programming.rst
unknown
edda7b58-bd69-4060-9295-d9036b4690eb
2,093
supabase-export-v2
d4d7421e812aff82
How do I cache method calls? ---------------------------- The two principal tools for caching methods are :func:`functools.cached_property` and :func:`functools.lru_cache`. The former stores results at the instance level and the latter at the class level.
trusted_official_docs
CPython Docs
How do I cache method calls? ---------------------------- The two principal tools for caching methods are :func:`functools.cached_property` and :func:`functools.lru_cache`. The former stores results at the instance level and the latter at the class level.
How do I cache method calls? ---------------------------- The two principal tools for caching methods are :func:`functools.cached_property` and :func:`functools.lru_cache`. The former stores results at the instance level and the latter at the class level.
python, official-docs, cpython, P0
Local_Trusted_Corpus
4a1e6524-7332-4922-8ad4-080aa02b4f41
CPython Docs
file://datasets/cpython/Doc/faq/programming.rst
unknown
edda7b58-bd69-4060-9295-d9036b4690eb
1,972
supabase-export-v2
356301291b1ce100
A method is a function on some object ``x`` that you normally call as ``x.name(arguments...)``. Methods are defined as functions inside the class definition:: class C: def meth(self, arg): return arg * 2 + self.attribute
trusted_official_docs
CPython Docs
A method is a function on some object ``x`` that you normally call as ``x.name(arguments...)``. Methods are defined as functions inside the class definition:: class C: def meth(self, arg): return arg * 2 + self.attribute
A method is a function on some object ``x`` that you normally call as ``x.name(arguments...)``. Methods are defined as functions inside the class definition:: class C: def meth(self, arg): return arg * 2 + self.attribute
python, official-docs, cpython, P0
Local_Trusted_Corpus
4ac53235-4718-48c1-8385-dc6b37abaf86
CPython Docs
file://datasets/cpython/Doc/faq/programming.rst
unknown
edda7b58-bd69-4060-9295-d9036b4690eb
1,957
supabase-export-v2
009610be1c07ff13
>>> result = a_list.__iadd__([1]) >>> a_list = result The object pointed to by a_list has been mutated, and the pointer to the mutated object is assigned back to ``a_list``. The end result of the assignment is a no-op, since it is a pointer to the same object that ``a_list`` was previously pointing to, but the assignme...
trusted_official_docs
CPython Docs
>>> result = a_list.__iadd__([1]) >>> a_list = result The object pointed to by a_list has been mutated, and the pointer to the mutated object is assigned back to ``a_list``. The end result of the assignment is a no-op, since it is a pointer to the same object that ``a_list`` was previously pointing to, but the assignme...
>>> result = a_list.__iadd__([1]) >>> a_list = result The object pointed to by a_list has been mutated, and the pointer to the mutated object is assigned back to ``a_list``. The end result of the assignment is a no-op, since it is a pointer to the same object that ``a_list`` was previously pointing to, but the assignme...
python, official-docs, cpython, P0
Local_Trusted_Corpus
4ae71fb9-1a6a-4222-ae44-6151ef854147
CPython Docs
file://datasets/cpython/Doc/faq/programming.rst
unknown
edda7b58-bd69-4060-9295-d9036b4690eb
1,930
supabase-export-v2
e9908216009daabb
This generates a list containing 3 different lists of length two. You can also use a list comprehension:: w, h = 2, 3 A = [[None] * w for i in range(h)]
trusted_official_docs
CPython Docs
This generates a list containing 3 different lists of length two. You can also use a list comprehension:: w, h = 2, 3 A = [[None] * w for i in range(h)]
This generates a list containing 3 different lists of length two. You can also use a list comprehension:: w, h = 2, 3 A = [[None] * w for i in range(h)]
python, official-docs, cpython, P0
Local_Trusted_Corpus
4af36c22-45d7-45a6-9c8a-7b4b8636c030
CPython Docs
file://datasets/cpython/Doc/faq/programming.rst
unknown
edda7b58-bd69-4060-9295-d9036b4690eb
1,907
supabase-export-v2
d97c8d80dcea2f02
condition is one possibility. However, it is easier and faster to use slice replacement with an implicit or explicit forward iteration. Here are three variations:: mylist[:] = filter(keep_function, mylist) mylist[:] = (x for x in mylist if keep_condition) mylist[:] = [x for x in mylist if keep_condition]
trusted_official_docs
CPython Docs
condition is one possibility. However, it is easier and faster to use slice replacement with an implicit or explicit forward iteration. Here are three variations:: mylist[:] = filter(keep_function, mylist) mylist[:] = (x for x in mylist if keep_condition) mylist[:] = [x for x in mylist if keep_condition]
condition is one possibility. However, it is easier and faster to use slice replacement with an implicit or explicit forward iteration. Here are three variations:: mylist[:] = filter(keep_function, mylist) mylist[:] = (x for x in mylist if keep_condition) mylist[:] = [x for x in mylist if keep_condition]
python, official-docs, cpython, P0
Local_Trusted_Corpus
4d76eb25-de75-4a42-ac93-bed1cb10dfb7
CPython Docs
file://datasets/cpython/Doc/faq/programming.rst
unknown
edda7b58-bd69-4060-9295-d9036b4690eb
1,960
supabase-export-v2
a876dcf188454b64
>>> result = a_tuple[0].__iadd__(['item']) >>> a_tuple[0] = result Traceback (most recent call last): ... TypeError: 'tuple' object does not support item assignment The :meth:`!__iadd__` succeeds, and thus the list is extended, but even though ``result`` points to the same object that ``a_tuple[0]`` already points to, ...
trusted_official_docs
CPython Docs
>>> result = a_tuple[0].__iadd__(['item']) >>> a_tuple[0] = result Traceback (most recent call last): ... TypeError: 'tuple' object does not support item assignment The :meth:`!__iadd__` succeeds, and thus the list is extended, but even though ``result`` points to the same object that ``a_tuple[0]`` already points to, ...
>>> result = a_tuple[0].__iadd__(['item']) >>> a_tuple[0] = result Traceback (most recent call last): ... TypeError: 'tuple' object does not support item assignment The :meth:`!__iadd__` succeeds, and thus the list is extended, but even though ``result`` points to the same object that ``a_tuple[0]`` already points to, ...
python, official-docs, cpython, P0
Local_Trusted_Corpus
4d9304b0-141f-45ac-bda9-3f8a38f428e5
CPython Docs
file://datasets/cpython/Doc/faq/programming.rst
unknown
edda7b58-bd69-4060-9295-d9036b4690eb
1,984
supabase-export-v2
b1e33ac5060bd26a
# Test for "true inheritance" >>> Mapping in type(c).__mro__ False Note that most programs do not use :func:`isinstance` on user-defined classes very often. If you are developing the classes yourself, a more proper object-oriented style is to define methods on the classes that encapsulate a particular behaviour, instea...
trusted_official_docs
CPython Docs
# Test for "true inheritance" >>> Mapping in type(c).__mro__ False Note that most programs do not use :func:`isinstance` on user-defined classes very often. If you are developing the classes yourself, a more proper object-oriented style is to define methods on the classes that encapsulate a particular behaviour, instea...
# Test for "true inheritance" >>> Mapping in type(c).__mro__ False Note that most programs do not use :func:`isinstance` on user-defined classes very often. If you are developing the classes yourself, a more proper object-oriented style is to define methods on the classes that encapsulate a particular behaviour, instea...
python, official-docs, cpython, P0
Local_Trusted_Corpus
4d96a3d7-541e-40a4-92ef-41520e88a334
CPython Docs
file://datasets/cpython/Doc/faq/programming.rst
unknown
edda7b58-bd69-4060-9295-d9036b4690eb
2,097
supabase-export-v2
a93a64bb8b3ee61c
approach works with methods that have :term:`hashable` arguments. It creates a reference to the instance unless special efforts are made to pass in weak references. The advantage of the least recently used algorithm is that the cache is bounded by the specified *maxsize*. The disadvantage is that instances are kept ali...
trusted_official_docs
CPython Docs
approach works with methods that have :term:`hashable` arguments. It creates a reference to the instance unless special efforts are made to pass in weak references. The advantage of the least recently used algorithm is that the cache is bounded by the specified *maxsize*. The disadvantage is that instances are kept ali...
approach works with methods that have :term:`hashable` arguments. It creates a reference to the instance unless special efforts are made to pass in weak references. The advantage of the least recently used algorithm is that the cache is bounded by the specified *maxsize*. The disadvantage is that instances are kept ali...
python, official-docs, cpython, P0
Local_Trusted_Corpus
50ac4bb2-ab31-4c86-b204-99ce396173d8
CPython Docs
file://datasets/cpython/Doc/faq/programming.rst
unknown
edda7b58-bd69-4060-9295-d9036b4690eb
1,633
supabase-export-v2
727d39f1e8840fba
How can I create a stand-alone binary from a Python script? ----------------------------------------------------------- You don't need the ability to compile Python to C code if all you want is a stand-alone program that users can download and run without having to install the Python distribution first. There are a num...
trusted_official_docs
CPython Docs
How can I create a stand-alone binary from a Python script? ----------------------------------------------------------- You don't need the ability to compile Python to C code if all you want is a stand-alone program that users can download and run without having to install the Python distribution first. There are a num...
How can I create a stand-alone binary from a Python script? ----------------------------------------------------------- You don't need the ability to compile Python to C code if all you want is a stand-alone program that users can download and run without having to install the Python distribution first. There are a num...
python, official-docs, cpython, P0
Local_Trusted_Corpus
523d6e3c-e343-464d-bd40-36c75906d924
CPython Docs
file://datasets/cpython/Doc/faq/programming.rst
unknown
edda7b58-bd69-4060-9295-d9036b4690eb
2,136
supabase-export-v2
1a5d8491d4ca82ca
no-op since there already is a module named ``foo``) * The import mechanism tries to read ``foo_var`` from ``foo`` globals, to set ``bar.foo_var = foo.foo_var`` The last step fails, because Python isn't done with interpreting ``foo`` yet and the global symbol dictionary for ``foo`` is still empty.
trusted_official_docs
CPython Docs
no-op since there already is a module named ``foo``) * The import mechanism tries to read ``foo_var`` from ``foo`` globals, to set ``bar.foo_var = foo.foo_var`` The last step fails, because Python isn't done with interpreting ``foo`` yet and the global symbol dictionary for ``foo`` is still empty.
no-op since there already is a module named ``foo``) * The import mechanism tries to read ``foo_var`` from ``foo`` globals, to set ``bar.foo_var = foo.foo_var`` The last step fails, because Python isn't done with interpreting ``foo`` yet and the global symbol dictionary for ``foo`` is still empty.
python, official-docs, cpython, P0
Local_Trusted_Corpus
52c41c9b-f97e-4446-a8d4-751274eb5c87
CPython Docs
file://datasets/cpython/Doc/faq/programming.rst
unknown
edda7b58-bd69-4060-9295-d9036b4690eb
1,773
supabase-export-v2
d28f38ecd9e3ceda
really care -- so the only way to find out what it's called is to ask all your neighbours (namespaces) if it's their cat (object)... ....and don't be surprised if you'll find that it's known by many names, or no name at all!
trusted_official_docs
CPython Docs
really care -- so the only way to find out what it's called is to ask all your neighbours (namespaces) if it's their cat (object)... ....and don't be surprised if you'll find that it's known by many names, or no name at all!
really care -- so the only way to find out what it's called is to ask all your neighbours (namespaces) if it's their cat (object)... ....and don't be surprised if you'll find that it's known by many names, or no name at all!
python, official-docs, cpython, P0
Local_Trusted_Corpus
53023790-267e-4c37-886c-92efab914dd7
CPython Docs
file://datasets/cpython/Doc/faq/programming.rst
unknown
edda7b58-bd69-4060-9295-d9036b4690eb
1,951
supabase-export-v2
e3b1edbacd33bbae
>>> a_tuple = (['foo'], 'bar') >>> a_tuple[0] += ['item'] Traceback (most recent call last): ... TypeError: 'tuple' object does not support item assignment The exception is a bit more surprising, and even more surprising is the fact that even though there was an error, the append worked::
trusted_official_docs
CPython Docs
>>> a_tuple = (['foo'], 'bar') >>> a_tuple[0] += ['item'] Traceback (most recent call last): ... TypeError: 'tuple' object does not support item assignment The exception is a bit more surprising, and even more surprising is the fact that even though there was an error, the append worked::
>>> a_tuple = (['foo'], 'bar') >>> a_tuple[0] += ['item'] Traceback (most recent call last): ... TypeError: 'tuple' object does not support item assignment The exception is a bit more surprising, and even more surprising is the fact that even though there was an error, the append worked::
python, official-docs, cpython, P0
Local_Trusted_Corpus
53c4d94d-1f47-4cd0-a72f-70bd1f78e792
CPython Docs
file://datasets/cpython/Doc/faq/programming.rst
unknown
edda7b58-bd69-4060-9295-d9036b4690eb
1,818
supabase-export-v2
471a07e0e3dd7810
How do I convert a string to a number? -------------------------------------- For integers, use the built-in :func:`int` type constructor, for example, ``int('144') == 144``. Similarly, :func:`float` converts to a floating-point number, for example, ``float('144') == 144.0``.
trusted_official_docs
CPython Docs
How do I convert a string to a number? -------------------------------------- For integers, use the built-in :func:`int` type constructor, for example, ``int('144') == 144``. Similarly, :func:`float` converts to a floating-point number, for example, ``float('144') == 144.0``.
How do I convert a string to a number? -------------------------------------- For integers, use the built-in :func:`int` type constructor, for example, ``int('144') == 144``. Similarly, :func:`float` converts to a floating-point number, for example, ``float('144') == 144.0``.
python, official-docs, cpython, P0
Local_Trusted_Corpus
5519f865-c741-4784-9466-764eb6107e3b
CPython Docs
file://datasets/cpython/Doc/faq/programming.rst
unknown
edda7b58-bd69-4060-9295-d9036b4690eb
1,812
supabase-export-v2
fb0056f75708c041
what did it say 200 hours ago? ``-190 % 12 == 2`` is useful; ``-190 % 12 == -10`` is a bug waiting to bite. How do I get int literal attribute instead of SyntaxError? ----------------------------------------------------------
trusted_official_docs
CPython Docs
what did it say 200 hours ago? ``-190 % 12 == 2`` is useful; ``-190 % 12 == -10`` is a bug waiting to bite. How do I get int literal attribute instead of SyntaxError? ----------------------------------------------------------
what did it say 200 hours ago? ``-190 % 12 == 2`` is useful; ``-190 % 12 == -10`` is a bug waiting to bite. How do I get int literal attribute instead of SyntaxError? ----------------------------------------------------------
python, official-docs, cpython, P0
Local_Trusted_Corpus
570f0fd4-d9fc-4b17-b1b2-2a54d4b9ae53
CPython Docs
file://datasets/cpython/Doc/faq/programming.rst
unknown
edda7b58-bd69-4060-9295-d9036b4690eb
1,621
supabase-export-v2
7f1eed1d66bd1fc6
The IDLE interactive development environment, which is part of the standard Python distribution (normally available as :mod:`idlelib`), includes a graphical debugger. PythonWin is a Python IDE that includes a GUI debugger based on pdb. The PythonWin debugger colors breakpoints and has quite a few cool features such as ...
trusted_official_docs
CPython Docs
The IDLE interactive development environment, which is part of the standard Python distribution (normally available as :mod:`idlelib`), includes a graphical debugger. PythonWin is a Python IDE that includes a GUI debugger based on pdb. The PythonWin debugger colors breakpoints and has quite a few cool features such as ...
The IDLE interactive development environment, which is part of the standard Python distribution (normally available as :mod:`idlelib`), includes a graphical debugger. PythonWin is a Python IDE that includes a GUI debugger based on pdb. The PythonWin debugger colors breakpoints and has quite a few cool features such as ...
python, official-docs, cpython, P0
Local_Trusted_Corpus
5842befc-962f-4685-81d8-f00818e3b51d
CPython Docs
file://datasets/cpython/Doc/faq/programming.rst
unknown
edda7b58-bd69-4060-9295-d9036b4690eb
2,125
supabase-export-v2
1c8040df0b3b9889
How do I find the current module name? -------------------------------------- A module can find out its own module name by looking at the predefined global variable ``__name__``. If this has the value ``'__main__'``, the program is running as a script. Many modules that are usually used by importing them also provide a...
trusted_official_docs
CPython Docs
How do I find the current module name? -------------------------------------- A module can find out its own module name by looking at the predefined global variable ``__name__``. If this has the value ``'__main__'``, the program is running as a script. Many modules that are usually used by importing them also provide a...
How do I find the current module name? -------------------------------------- A module can find out its own module name by looking at the predefined global variable ``__name__``. If this has the value ``'__main__'``, the program is running as a script. Many modules that are usually used by importing them also provide a...
python, official-docs, cpython, P0
Local_Trusted_Corpus
59108e92-d821-4c21-abc2-fb1999970710
CPython Docs
file://datasets/cpython/Doc/faq/programming.rst
unknown
edda7b58-bd69-4060-9295-d9036b4690eb
2,121
supabase-export-v2
476fdf01707759dd
>>> import py_compile >>> py_compile.compile('foo.py') # doctest: +SKIP This will write the ``.pyc`` to a ``__pycache__`` subdirectory in the same location as ``foo.py`` (or you can override that with the optional parameter *cfile*).
trusted_official_docs
CPython Docs
>>> import py_compile >>> py_compile.compile('foo.py') # doctest: +SKIP This will write the ``.pyc`` to a ``__pycache__`` subdirectory in the same location as ``foo.py`` (or you can override that with the optional parameter *cfile*).
>>> import py_compile >>> py_compile.compile('foo.py') # doctest: +SKIP This will write the ``.pyc`` to a ``__pycache__`` subdirectory in the same location as ``foo.py`` (or you can override that with the optional parameter *cfile*).
python, official-docs, cpython, P0
Local_Trusted_Corpus
5a078285-6031-4dfc-8234-db489651fb32
CPython Docs
file://datasets/cpython/Doc/faq/programming.rst
unknown
edda7b58-bd69-4060-9295-d9036b4690eb
1,737
supabase-export-v2
a711cb5acf01f26f
4) By passing in a dictionary that gets mutated:: >>> def func3(args): ... args['a'] = 'new-value' # args is a mutable dictionary ... args['b'] = args['b'] + 1 # change it in-place ... >>> args = {'a': 'old-value', 'b': 99} >>> func3(args) >>> args {'a': 'new-value', 'b': 100}
trusted_official_docs
CPython Docs
4) By passing in a dictionary that gets mutated:: >>> def func3(args): ... args['a'] = 'new-value' # args is a mutable dictionary ... args['b'] = args['b'] + 1 # change it in-place ... >>> args = {'a': 'old-value', 'b': 99} >>> func3(args) >>> args {'a': 'new-value', 'b': 100}
4) By passing in a dictionary that gets mutated:: >>> def func3(args): ... args['a'] = 'new-value' # args is a mutable dictionary ... args['b'] = args['b'] + 1 # change it in-place ... >>> args = {'a': 'old-value', 'b': 99} >>> func3(args) >>> args {'a': 'new-value', 'b': 100}
python, official-docs, cpython, P0
Local_Trusted_Corpus
5dd6b3dc-6e11-41be-ac3e-c0c91ba63a35
CPython Docs
file://datasets/cpython/Doc/faq/programming.rst
unknown
edda7b58-bd69-4060-9295-d9036b4690eb
1,869
supabase-export-v2
64094798ed521542
That's a tough one, in general. First, here is a list of things to remember before diving further: * Performance characteristics vary across Python implementations. This FAQ focuses on :term:`CPython`. * Behaviour can vary across operating systems, especially when talking about I/O or multi-threading. * You should al...
trusted_official_docs
CPython Docs
That's a tough one, in general. First, here is a list of things to remember before diving further: * Performance characteristics vary across Python implementations. This FAQ focuses on :term:`CPython`. * Behaviour can vary across operating systems, especially when talking about I/O or multi-threading. * You should al...
That's a tough one, in general. First, here is a list of things to remember before diving further: * Performance characteristics vary across Python implementations. This FAQ focuses on :term:`CPython`. * Behaviour can vary across operating systems, especially when talking about I/O or multi-threading. * You should al...
python, official-docs, cpython, P0
Local_Trusted_Corpus
5f125c59-8fb7-4a57-bed1-34b4ceac2895
CPython Docs
file://datasets/cpython/Doc/faq/programming.rst
unknown
edda7b58-bd69-4060-9295-d9036b4690eb
2,035
supabase-export-v2
a07a7bb89f374cd5
I try to use __spam and I get an error about _SomeClassName__spam. ------------------------------------------------------------------ Variable names with double leading underscores are "mangled" to provide a simple but effective way to define class private variables. Any identifier of the form ``__spam`` (at least two ...
trusted_official_docs
CPython Docs
I try to use __spam and I get an error about _SomeClassName__spam. ------------------------------------------------------------------ Variable names with double leading underscores are "mangled" to provide a simple but effective way to define class private variables. Any identifier of the form ``__spam`` (at least two ...
I try to use __spam and I get an error about _SomeClassName__spam. ------------------------------------------------------------------ Variable names with double leading underscores are "mangled" to provide a simple but effective way to define class private variables. Any identifier of the form ``__spam`` (at least two ...
python, official-docs, cpython, P0
Local_Trusted_Corpus
5fc7e547-4a66-4740-8409-f576eaf14b0c
CPython Docs
file://datasets/cpython/Doc/faq/programming.rst
unknown
edda7b58-bd69-4060-9295-d9036b4690eb
1,701
supabase-export-v2
80596e94c153344a
# Calculate the value result = ... expensive computation ... _cache[(arg1, arg2)] = result # Store result in the cache return result You could use a global variable containing a dictionary instead of the default value; it's a matter of taste.
trusted_official_docs
CPython Docs
# Calculate the value result = ... expensive computation ... _cache[(arg1, arg2)] = result # Store result in the cache return result You could use a global variable containing a dictionary instead of the default value; it's a matter of taste.
# Calculate the value result = ... expensive computation ... _cache[(arg1, arg2)] = result # Store result in the cache return result You could use a global variable containing a dictionary instead of the default value; it's a matter of taste.
python, official-docs, cpython, P0
Local_Trusted_Corpus
60c66e10-80c2-4f13-8ba6-8f7de26fe066
CPython Docs
file://datasets/cpython/Doc/faq/programming.rst
unknown
edda7b58-bd69-4060-9295-d9036b4690eb
1,902
supabase-export-v2
36dd8f6c99f02a93
if mylist: mylist.sort() last = mylist[-1] for i in range(len(mylist)-2, -1, -1): if last == mylist[i]: del mylist[i] else: last = mylist[i] If all elements of the list may be used as set keys (that is, they are all :term:`hashable`) this is often faster::
trusted_official_docs
CPython Docs
if mylist: mylist.sort() last = mylist[-1] for i in range(len(mylist)-2, -1, -1): if last == mylist[i]: del mylist[i] else: last = mylist[i] If all elements of the list may be used as set keys (that is, they are all :term:`hashable`) this is often faster::
if mylist: mylist.sort() last = mylist[-1] for i in range(len(mylist)-2, -1, -1): if last == mylist[i]: del mylist[i] else: last = mylist[i] If all elements of the list may be used as set keys (that is, they are all :term:`hashable`) this is often faster::
python, official-docs, cpython, P0
Local_Trusted_Corpus
623c9db5-778d-494d-88a7-fb56a7eef64a
CPython Docs
file://datasets/cpython/Doc/faq/programming.rst
unknown
edda7b58-bd69-4060-9295-d9036b4690eb
1,927
supabase-export-v2
28388f06b440bb48
references to the same list of length two. Changes to one row will show in all rows, which is almost certainly not what you want. The suggested approach is to create a list of the desired length first and then fill in each element with a newly created list::
trusted_official_docs
CPython Docs
references to the same list of length two. Changes to one row will show in all rows, which is almost certainly not what you want. The suggested approach is to create a list of the desired length first and then fill in each element with a newly created list::
references to the same list of length two. Changes to one row will show in all rows, which is almost certainly not what you want. The suggested approach is to create a list of the desired length first and then fill in each element with a newly created list::
python, official-docs, cpython, P0
Local_Trusted_Corpus
632df455-5903-4ce4-a6cd-6c985ed59168
CPython Docs
file://datasets/cpython/Doc/faq/programming.rst
unknown
edda7b58-bd69-4060-9295-d9036b4690eb
1,784
supabase-export-v2
c3227130da74f30c
x, y = 50, 25 small = x if x < y else y Before this syntax was introduced in Python 2.5, a common idiom was to use logical operators::
trusted_official_docs
CPython Docs
x, y = 50, 25 small = x if x < y else y Before this syntax was introduced in Python 2.5, a common idiom was to use logical operators::
x, y = 50, 25 small = x if x < y else y Before this syntax was introduced in Python 2.5, a common idiom was to use logical operators::
python, official-docs, cpython, P0
Local_Trusted_Corpus
6331569a-55ff-462c-ac4f-9abd890190eb
CPython Docs
file://datasets/cpython/Doc/faq/programming.rst
unknown
edda7b58-bd69-4060-9295-d9036b4690eb
1,819
supabase-export-v2
00f2b552aff97836
For integers, use the built-in :func:`int` type constructor, for example, ``int('144') == 144``. Similarly, :func:`float` converts to a floating-point number, for example, ``float('144') == 144.0``. By default, these interpret the number as decimal, so that ``int('0144') == 144`` holds true, and ``int('0x144')`` raises...
trusted_official_docs
CPython Docs
For integers, use the built-in :func:`int` type constructor, for example, ``int('144') == 144``. Similarly, :func:`float` converts to a floating-point number, for example, ``float('144') == 144.0``. By default, these interpret the number as decimal, so that ``int('0144') == 144`` holds true, and ``int('0x144')`` raises...
For integers, use the built-in :func:`int` type constructor, for example, ``int('144') == 144``. Similarly, :func:`float` converts to a floating-point number, for example, ``float('144') == 144.0``. By default, these interpret the number as decimal, so that ``int('0144') == 144`` holds true, and ``int('0x144')`` raises...
python, official-docs, cpython, P0
Local_Trusted_Corpus
64fb5015-855e-464f-9c84-4cf9ecfe2381
CPython Docs
file://datasets/cpython/Doc/faq/programming.rst
unknown
edda7b58-bd69-4060-9295-d9036b4690eb
1,977
supabase-export-v2
1ae0055ff0760acc
How do I check if an object is an instance of a given class or of a subclass of it? ----------------------------------------------------------------------------------- Use the built-in function :func:`isinstance(obj, cls) <isinstance>`. You can check if an object is an instance of any of a number of classes by providin...
trusted_official_docs
CPython Docs
How do I check if an object is an instance of a given class or of a subclass of it? ----------------------------------------------------------------------------------- Use the built-in function :func:`isinstance(obj, cls) <isinstance>`. You can check if an object is an instance of any of a number of classes by providin...
How do I check if an object is an instance of a given class or of a subclass of it? ----------------------------------------------------------------------------------- Use the built-in function :func:`isinstance(obj, cls) <isinstance>`. You can check if an object is an instance of any of a number of classes by providin...
python, official-docs, cpython, P0
Local_Trusted_Corpus
65314977-ae24-48e7-ae4d-767dcf4ad6f9
CPython Docs
file://datasets/cpython/Doc/faq/programming.rst
unknown
edda7b58-bd69-4060-9295-d9036b4690eb
1,906
supabase-export-v2
10c1cf5ee4d1cb4b
How do you remove multiple items from a list? --------------------------------------------- As with removing duplicates, explicitly iterating in reverse with a delete condition is one possibility. However, it is easier and faster to use slice replacement with an implicit or explicit forward iteration. Here are three va...
trusted_official_docs
CPython Docs
How do you remove multiple items from a list? --------------------------------------------- As with removing duplicates, explicitly iterating in reverse with a delete condition is one possibility. However, it is easier and faster to use slice replacement with an implicit or explicit forward iteration. Here are three va...
How do you remove multiple items from a list? --------------------------------------------- As with removing duplicates, explicitly iterating in reverse with a delete condition is one possibility. However, it is easier and faster to use slice replacement with an implicit or explicit forward iteration. Here are three va...
python, official-docs, cpython, P0
Local_Trusted_Corpus
6879b584-3aee-4a80-9b27-de1a5da7e58e
CPython Docs
file://datasets/cpython/Doc/faq/programming.rst
unknown
edda7b58-bd69-4060-9295-d9036b4690eb
1,652
supabase-export-v2
3429e7cec6ffd766
In the example above you can access the outer scope variable by declaring it global: >>> x = 10 >>> def foobar(): ... global x ... print(x) ... x += 1 ... >>> foobar() 10
trusted_official_docs
CPython Docs
In the example above you can access the outer scope variable by declaring it global: >>> x = 10 >>> def foobar(): ... global x ... print(x) ... x += 1 ... >>> foobar() 10
In the example above you can access the outer scope variable by declaring it global: >>> x = 10 >>> def foobar(): ... global x ... print(x) ... x += 1 ... >>> foobar() 10
python, official-docs, cpython, P0
Local_Trusted_Corpus
689424fc-baf8-4213-b5a7-e61796dbf941
CPython Docs
file://datasets/cpython/Doc/faq/programming.rst
unknown
edda7b58-bd69-4060-9295-d9036b4690eb
1,875
supabase-export-v2
f279678aeb087b37
program will be slower. You should avoid excessive abstraction, especially under the form of tiny functions or methods (which are also often detrimental to readability). If you have reached the limit of what pure Python can allow, there are tools to take you further away. For example, `Cython <https://cython.org>`_ can...
trusted_official_docs
CPython Docs
program will be slower. You should avoid excessive abstraction, especially under the form of tiny functions or methods (which are also often detrimental to readability). If you have reached the limit of what pure Python can allow, there are tools to take you further away. For example, `Cython <https://cython.org>`_ can...
program will be slower. You should avoid excessive abstraction, especially under the form of tiny functions or methods (which are also often detrimental to readability). If you have reached the limit of what pure Python can allow, there are tools to take you further away. For example, `Cython <https://cython.org>`_ can...
python, official-docs, cpython, P0
Local_Trusted_Corpus
69549d09-fc04-444e-9a1d-1e4dcc1da1a4
CPython Docs
file://datasets/cpython/Doc/faq/programming.rst
unknown
edda7b58-bd69-4060-9295-d9036b4690eb
1,663
supabase-export-v2
acf69493e869f38e
>>> squares = [] >>> for x in range(5): ... squares.append(lambda: x**2) This gives you a list that contains 5 lambdas that calculate ``x**2``. You might expect that, when called, they would return, respectively, ``0``, ``1``, ``4``, ``9``, and ``16``. However, when you actually try you will see that they all return ``...
trusted_official_docs
CPython Docs
>>> squares = [] >>> for x in range(5): ... squares.append(lambda: x**2) This gives you a list that contains 5 lambdas that calculate ``x**2``. You might expect that, when called, they would return, respectively, ``0``, ``1``, ``4``, ``9``, and ``16``. However, when you actually try you will see that they all return ``...
>>> squares = [] >>> for x in range(5): ... squares.append(lambda: x**2) This gives you a list that contains 5 lambdas that calculate ``x**2``. You might expect that, when called, they would return, respectively, ``0``, ``1``, ``4``, ``9``, and ``16``. However, when you actually try you will see that they all return ``...
python, official-docs, cpython, P0
Local_Trusted_Corpus
695e3c05-3200-4c42-862b-2412ebf0589e
CPython Docs
file://datasets/cpython/Doc/faq/programming.rst
unknown
edda7b58-bd69-4060-9295-d9036b4690eb
1,870
supabase-export-v2
4d7a6aea599f5a07
* It is highly recommended to have good code coverage (through unit testing or any other technique) before potentially introducing regressions hidden in sophisticated optimizations. That being said, there are many tricks to speed up Python code. Here are some general principles which go a long way towards reaching acce...
trusted_official_docs
CPython Docs
* It is highly recommended to have good code coverage (through unit testing or any other technique) before potentially introducing regressions hidden in sophisticated optimizations. That being said, there are many tricks to speed up Python code. Here are some general principles which go a long way towards reaching acce...
* It is highly recommended to have good code coverage (through unit testing or any other technique) before potentially introducing regressions hidden in sophisticated optimizations. That being said, there are many tricks to speed up Python code. Here are some general principles which go a long way towards reaching acce...
python, official-docs, cpython, P0
Local_Trusted_Corpus
69904f47-c9b2-43e3-8315-94402644a0f7
CPython Docs
file://datasets/cpython/Doc/faq/programming.rst
unknown
edda7b58-bd69-4060-9295-d9036b4690eb
1,651
supabase-export-v2
a1a85b346d6c48f0
``x``, the compiler recognizes it as a local variable. Consequently when the earlier ``print(x)`` attempts to print the uninitialized local variable and an error results. In the example above you can access the outer scope variable by declaring it global:
trusted_official_docs
CPython Docs
``x``, the compiler recognizes it as a local variable. Consequently when the earlier ``print(x)`` attempts to print the uninitialized local variable and an error results. In the example above you can access the outer scope variable by declaring it global:
``x``, the compiler recognizes it as a local variable. Consequently when the earlier ``print(x)`` attempts to print the uninitialized local variable and an error results. In the example above you can access the outer scope variable by declaring it global:
python, official-docs, cpython, P0
Local_Trusted_Corpus
69e2250d-e557-4da9-8f94-432a60d2e6c7
CPython Docs
file://datasets/cpython/Doc/faq/programming.rst
unknown
edda7b58-bd69-4060-9295-d9036b4690eb
2,116
supabase-export-v2
abd7a09949749d81
This can happen, for example, if you develop as one user but run as another, such as if you are testing with a web server. Unless the :envvar:`PYTHONDONTWRITEBYTECODE` environment variable is set, creation of a .pyc file is automatic if you're importing a module and Python has the ability (permissions, free space, and ...
trusted_official_docs
CPython Docs
This can happen, for example, if you develop as one user but run as another, such as if you are testing with a web server. Unless the :envvar:`PYTHONDONTWRITEBYTECODE` environment variable is set, creation of a .pyc file is automatic if you're importing a module and Python has the ability (permissions, free space, and ...
This can happen, for example, if you develop as one user but run as another, such as if you are testing with a web server. Unless the :envvar:`PYTHONDONTWRITEBYTECODE` environment variable is set, creation of a .pyc file is automatic if you're importing a module and Python has the ability (permissions, free space, and ...
python, official-docs, cpython, P0
Local_Trusted_Corpus
6a9c1666-e143-4755-92fc-713e6c6fdba6
CPython Docs
file://datasets/cpython/Doc/faq/programming.rst
unknown
edda7b58-bd69-4060-9295-d9036b4690eb
1,685
supabase-export-v2
2f5e46c874cd1638
It is sometimes necessary to move imports to a function or class to avoid problems with circular imports. Gordon McMillan says: Circular imports are fine where both modules use the "import <module>" form of import. They fail when the 2nd module wants to grab a name out of the first ("from module import name") and the...
trusted_official_docs
CPython Docs
It is sometimes necessary to move imports to a function or class to avoid problems with circular imports. Gordon McMillan says: Circular imports are fine where both modules use the "import <module>" form of import. They fail when the 2nd module wants to grab a name out of the first ("from module import name") and the...
It is sometimes necessary to move imports to a function or class to avoid problems with circular imports. Gordon McMillan says: Circular imports are fine where both modules use the "import <module>" form of import. They fail when the 2nd module wants to grab a name out of the first ("from module import name") and the...
python, official-docs, cpython, P0
Local_Trusted_Corpus
6b2cf1bf-bb4c-4a3e-b96a-4b10962b5ec6
CPython Docs
file://datasets/cpython/Doc/faq/programming.rst
unknown
edda7b58-bd69-4060-9295-d9036b4690eb
2,141
supabase-export-v2
bb65447e1af9bc9b
Jim Roskind suggests performing steps in the following order in each module: * exports (globals, functions, and classes that don't need imported base classes) * ``import`` statements * active code (including globals that are initialized from imported values).
trusted_official_docs
CPython Docs
Jim Roskind suggests performing steps in the following order in each module: * exports (globals, functions, and classes that don't need imported base classes) * ``import`` statements * active code (including globals that are initialized from imported values).
Jim Roskind suggests performing steps in the following order in each module: * exports (globals, functions, and classes that don't need imported base classes) * ``import`` statements * active code (including globals that are initialized from imported values).
python, official-docs, cpython, P0
Local_Trusted_Corpus
6bccc231-49a6-44f2-b2c3-54c1874c78d3
CPython Docs
file://datasets/cpython/Doc/faq/programming.rst
unknown
edda7b58-bd69-4060-9295-d9036b4690eb
1,820
supabase-export-v2
19f5fa1c324122b3
If the base is specified as 0, the number is interpreted using Python's rules: a leading '0o' indicates octal, and '0x' indicates a hex number. Do not use the built-in function :func:`eval` if all you need is to convert strings to numbers. :func:`eval` will be significantly slower and it presents a security risk: someo...
trusted_official_docs
CPython Docs
If the base is specified as 0, the number is interpreted using Python's rules: a leading '0o' indicates octal, and '0x' indicates a hex number. Do not use the built-in function :func:`eval` if all you need is to convert strings to numbers. :func:`eval` will be significantly slower and it presents a security risk: someo...
If the base is specified as 0, the number is interpreted using Python's rules: a leading '0o' indicates octal, and '0x' indicates a hex number. Do not use the built-in function :func:`eval` if all you need is to convert strings to numbers. :func:`eval` will be significantly slower and it presents a security risk: someo...
python, official-docs, cpython, P0
Local_Trusted_Corpus
6cd8b29e-7e0b-4828-87a2-b5c9e119ea59
CPython Docs
file://datasets/cpython/Doc/faq/programming.rst
unknown
edda7b58-bd69-4060-9295-d9036b4690eb
1,874
supabase-export-v2
996a0d1e00d7b031
to use either the :meth:`list.sort` built-in method or the related :func:`sorted` function to do sorting (and see the :ref:`sortinghowto` for examples of moderately advanced usage). * Abstractions tend to create indirections and force the interpreter to work more. If the levels of indirection outweigh the amount of us...
trusted_official_docs
CPython Docs
to use either the :meth:`list.sort` built-in method or the related :func:`sorted` function to do sorting (and see the :ref:`sortinghowto` for examples of moderately advanced usage). * Abstractions tend to create indirections and force the interpreter to work more. If the levels of indirection outweigh the amount of us...
to use either the :meth:`list.sort` built-in method or the related :func:`sorted` function to do sorting (and see the :ref:`sortinghowto` for examples of moderately advanced usage). * Abstractions tend to create indirections and force the interpreter to work more. If the levels of indirection outweigh the amount of us...
python, official-docs, cpython, P0
Local_Trusted_Corpus
6dd1669d-350d-47ad-ae92-4af9233eac47
CPython Docs
file://datasets/cpython/Doc/faq/programming.rst
unknown
edda7b58-bd69-4060-9295-d9036b4690eb
2,115
supabase-export-v2
753081b249ad9098
the ``.py`` file, and ends with ``.pyc``, with a middle component that depends on the particular ``python`` binary that created it. (See :pep:`3147` for details.) One reason that a ``.pyc`` file may not be created is a permissions problem with the directory containing the source file, meaning that the ``__pycache__`` s...
trusted_official_docs
CPython Docs
the ``.py`` file, and ends with ``.pyc``, with a middle component that depends on the particular ``python`` binary that created it. (See :pep:`3147` for details.) One reason that a ``.pyc`` file may not be created is a permissions problem with the directory containing the source file, meaning that the ``__pycache__`` s...
the ``.py`` file, and ends with ``.pyc``, with a middle component that depends on the particular ``python`` binary that created it. (See :pep:`3147` for details.) One reason that a ``.pyc`` file may not be created is a permissions problem with the directory containing the source file, meaning that the ``__pycache__`` s...
python, official-docs, cpython, P0
Local_Trusted_Corpus
6e43ced9-7507-4947-8707-72f3cf1813a6
CPython Docs
file://datasets/cpython/Doc/faq/programming.rst
unknown
edda7b58-bd69-4060-9295-d9036b4690eb
1,890
supabase-export-v2
9d53df0a75866452
3))`` yields ``[1, 2, 3]`` and ``list('abc')`` yields ``['a', 'b', 'c']``. If the argument is a list, it makes a copy just like ``seq[:]`` would. What's a negative index? ------------------------
trusted_official_docs
CPython Docs
3))`` yields ``[1, 2, 3]`` and ``list('abc')`` yields ``['a', 'b', 'c']``. If the argument is a list, it makes a copy just like ``seq[:]`` would. What's a negative index? ------------------------
3))`` yields ``[1, 2, 3]`` and ``list('abc')`` yields ``['a', 'b', 'c']``. If the argument is a list, it makes a copy just like ``seq[:]`` would. What's a negative index? ------------------------
python, official-docs, cpython, P0
Local_Trusted_Corpus
6e92bcd9-10e5-4ab0-be25-0e8d90d6bd8a
CPython Docs
file://datasets/cpython/Doc/faq/programming.rst
unknown
edda7b58-bd69-4060-9295-d9036b4690eb
1,808
supabase-export-v2
09104c7e03920b70
Why does -22 // 10 return -3? ----------------------------- It's primarily driven by the desire that ``i % j`` have the same sign as ``j``. If you want that, and also want::
trusted_official_docs
CPython Docs
Why does -22 // 10 return -3? ----------------------------- It's primarily driven by the desire that ``i % j`` have the same sign as ``j``. If you want that, and also want::
Why does -22 // 10 return -3? ----------------------------- It's primarily driven by the desire that ``i % j`` have the same sign as ``j``. If you want that, and also want::
python, official-docs, cpython, P0
Local_Trusted_Corpus
6f62de33-a813-4b65-b831-5c40e7203cb1
CPython Docs
file://datasets/cpython/Doc/faq/programming.rst
unknown
edda7b58-bd69-4060-9295-d9036b4690eb
2,155
supabase-export-v2
79c2fd7e28e3b6af
cls >>> c = cls.C() # Create an instance of C >>> importlib.reload(cls) <module 'cls' from 'cls.py'> >>> isinstance(c, cls.C) # isinstance is false?!? False The nature of the problem is made clear if you print out the "identity" of the class objects::
trusted_official_docs
CPython Docs
cls >>> c = cls.C() # Create an instance of C >>> importlib.reload(cls) <module 'cls' from 'cls.py'> >>> isinstance(c, cls.C) # isinstance is false?!? False The nature of the problem is made clear if you print out the "identity" of the class objects::
cls >>> c = cls.C() # Create an instance of C >>> importlib.reload(cls) <module 'cls' from 'cls.py'> >>> isinstance(c, cls.C) # isinstance is false?!? False The nature of the problem is made clear if you print out the "identity" of the class objects::
python, official-docs, cpython, P0
Local_Trusted_Corpus
713f7964-d5a2-445d-8686-b559e66b2be8
CPython Docs
file://datasets/cpython/Doc/faq/programming.rst
unknown
edda7b58-bd69-4060-9295-d9036b4690eb
2,119
supabase-export-v2
1aff0e540adc520b
``foo`` -- that is, to create a ``.pyc`` file for a module that is not imported -- you can, using the :mod:`py_compile` and :mod:`compileall` modules. The :mod:`py_compile` module can manually compile any module. One way is to use the ``compile()`` function in that module interactively::
trusted_official_docs
CPython Docs
``foo`` -- that is, to create a ``.pyc`` file for a module that is not imported -- you can, using the :mod:`py_compile` and :mod:`compileall` modules. The :mod:`py_compile` module can manually compile any module. One way is to use the ``compile()`` function in that module interactively::
``foo`` -- that is, to create a ``.pyc`` file for a module that is not imported -- you can, using the :mod:`py_compile` and :mod:`compileall` modules. The :mod:`py_compile` module can manually compile any module. One way is to use the ``compile()`` function in that module interactively::
python, official-docs, cpython, P0
Local_Trusted_Corpus
716508dd-0609-439f-ab63-45d91b49588a
CPython Docs
file://datasets/cpython/Doc/faq/programming.rst
unknown
edda7b58-bd69-4060-9295-d9036b4690eb
1,708
supabase-export-v2
87b2416f8194e077
What is the difference between arguments and parameters? -------------------------------------------------------- :term:`Parameters <parameter>` are defined by the names that appear in a function definition, whereas :term:`arguments <argument>` are the values actually passed to a function when calling it. Parameters de...
trusted_official_docs
CPython Docs
What is the difference between arguments and parameters? -------------------------------------------------------- :term:`Parameters <parameter>` are defined by the names that appear in a function definition, whereas :term:`arguments <argument>` are the values actually passed to a function when calling it. Parameters de...
What is the difference between arguments and parameters? -------------------------------------------------------- :term:`Parameters <parameter>` are defined by the names that appear in a function definition, whereas :term:`arguments <argument>` are the values actually passed to a function when calling it. Parameters de...
python, official-docs, cpython, P0
Local_Trusted_Corpus
732b0046-71be-4852-a53d-feabf516a203
CPython Docs
file://datasets/cpython/Doc/faq/programming.rst
unknown
edda7b58-bd69-4060-9295-d9036b4690eb
1,689
supabase-export-v2
c01d565d4f799c86
free, costing only a couple of dictionary lookups. Even if the module name has gone out of scope, the module is probably available in :data:`sys.modules`. Why are default values shared between objects? ----------------------------------------------
trusted_official_docs
CPython Docs
free, costing only a couple of dictionary lookups. Even if the module name has gone out of scope, the module is probably available in :data:`sys.modules`. Why are default values shared between objects? ----------------------------------------------
free, costing only a couple of dictionary lookups. Even if the module name has gone out of scope, the module is probably available in :data:`sys.modules`. Why are default values shared between objects? ----------------------------------------------
python, official-docs, cpython, P0
Local_Trusted_Corpus
732fc06b-5272-4a05-8865-a9fb18e8e6ea
CPython Docs
file://datasets/cpython/Doc/faq/programming.rst
unknown
edda7b58-bd69-4060-9295-d9036b4690eb
1,681
supabase-export-v2
040af6da57d2193f
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. Import modules at the top of a file. Doing so makes it clear what other modules your code requires and avoids questions of whether the module name is in scope. ...
trusted_official_docs
CPython Docs
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. Import modules at the top of a file. Doing so makes it clear what other modules your code requires and avoids questions of whether the module name is in scope. ...
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. Import modules at the top of a file. Doing so makes it clear what other modules your code requires and avoids questions of whether the module name is in scope. ...
python, official-docs, cpython, P0
Local_Trusted_Corpus
74554f2f-ab85-4312-bf95-bdf70cd900f5
CPython Docs
file://datasets/cpython/Doc/faq/programming.rst
unknown
edda7b58-bd69-4060-9295-d9036b4690eb
2,047
supabase-export-v2
0d42d49b26cc3b09
The :keyword:`del` statement does not necessarily call :meth:`~object.__del__` -- it simply decrements the object's reference count, and if this reaches zero :meth:`!__del__` is called. If your data structures contain circular links (for example, a tree where each child has a parent reference and each parent has a list...
trusted_official_docs
CPython Docs
The :keyword:`del` statement does not necessarily call :meth:`~object.__del__` -- it simply decrements the object's reference count, and if this reaches zero :meth:`!__del__` is called. If your data structures contain circular links (for example, a tree where each child has a parent reference and each parent has a list...
The :keyword:`del` statement does not necessarily call :meth:`~object.__del__` -- it simply decrements the object's reference count, and if this reaches zero :meth:`!__del__` is called. If your data structures contain circular links (for example, a tree where each child has a parent reference and each parent has a list...
python, official-docs, cpython, P0
Local_Trusted_Corpus
74d0c957-3afc-4c65-919c-6e285d6d6946
CPython Docs
file://datasets/cpython/Doc/faq/programming.rst
unknown
edda7b58-bd69-4060-9295-d9036b4690eb
2,075
supabase-export-v2
56dcd2e112b8aaaf
check for ``None``. This reads like plain English in code and avoids confusion with other objects that may have boolean values that evaluate to false. 2) Detecting optional arguments can be tricky when ``None`` is a valid input value. In those situations, you can create a singleton sentinel object guaranteed to be di...
trusted_official_docs
CPython Docs
check for ``None``. This reads like plain English in code and avoids confusion with other objects that may have boolean values that evaluate to false. 2) Detecting optional arguments can be tricky when ``None`` is a valid input value. In those situations, you can create a singleton sentinel object guaranteed to be di...
check for ``None``. This reads like plain English in code and avoids confusion with other objects that may have boolean values that evaluate to false. 2) Detecting optional arguments can be tricky when ``None`` is a valid input value. In those situations, you can create a singleton sentinel object guaranteed to be di...
python, official-docs, cpython, P0
Local_Trusted_Corpus
75798145-6b84-4f8a-8a61-8a7eef016385
CPython Docs
file://datasets/cpython/Doc/faq/programming.rst
unknown
edda7b58-bd69-4060-9295-d9036b4690eb
1,724
supabase-export-v2
cfdf68fe13aedfc2
give you a sorted copy of ``y``, you'll instead end up with ``None``, which will likely cause your program to generate an easily diagnosed error. However, there is one class of operations where the same operation sometimes has different behaviors with different types: the augmented assignment operators. For example, ``...
trusted_official_docs
CPython Docs
give you a sorted copy of ``y``, you'll instead end up with ``None``, which will likely cause your program to generate an easily diagnosed error. However, there is one class of operations where the same operation sometimes has different behaviors with different types: the augmented assignment operators. For example, ``...
give you a sorted copy of ``y``, you'll instead end up with ``None``, which will likely cause your program to generate an easily diagnosed error. However, there is one class of operations where the same operation sometimes has different behaviors with different types: the augmented assignment operators. For example, ``...
python, official-docs, cpython, P0
Local_Trusted_Corpus