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
53381b50-7889-4bb5-88b4-56aa4bc6c030
CPython Docs
file://datasets/cpython/Doc/tutorial/errors.rst
unknown
3d4c648c-7ce3-4a72-a411-a7b59c82fde0
54,078
supabase-export-v2
8f6f328b10dd4cea
by an :keyword:`except` clause. If the exception is not handled by an :keyword:`!except` clause, the exception is re-raised after the :keyword:`!finally` clause has been executed. * An exception could occur during execution of an :keyword:`!except` or :keyword:`!else` clause. Again, the exception is re-raised after t...
trusted_official_docs
CPython Docs
by an :keyword:`except` clause. If the exception is not handled by an :keyword:`!except` clause, the exception is re-raised after the :keyword:`!finally` clause has been executed. * An exception could occur during execution of an :keyword:`!except` or :keyword:`!else` clause. Again, the exception is re-raised after t...
by an :keyword:`except` clause. If the exception is not handled by an :keyword:`!except` clause, the exception is re-raised after the :keyword:`!finally` clause has been executed. * An exception could occur during execution of an :keyword:`!except` or :keyword:`!else` clause. Again, the exception is re-raised after t...
python, official-docs, cpython, P0
Local_Trusted_Corpus
5b1cc710-2539-4c69-95e8-6e76984e7727
CPython Docs
file://datasets/cpython/Doc/tutorial/errors.rst
unknown
3d4c648c-7ce3-4a72-a411-a7b59c82fde0
54,075
supabase-export-v2
0017917d41242940
The :keyword:`try` statement has another optional clause which is intended to define clean-up actions that must be executed under all circumstances. For example:: >>> try: ... raise KeyboardInterrupt ... finally: ... print('Goodbye, world!') ... Goodbye, world! Traceback (most recent call last): File "<stdin>", li...
trusted_official_docs
CPython Docs
The :keyword:`try` statement has another optional clause which is intended to define clean-up actions that must be executed under all circumstances. For example:: >>> try: ... raise KeyboardInterrupt ... finally: ... print('Goodbye, world!') ... Goodbye, world! Traceback (most recent call last): File "<stdin>", li...
The :keyword:`try` statement has another optional clause which is intended to define clean-up actions that must be executed under all circumstances. For example:: >>> try: ... raise KeyboardInterrupt ... finally: ... print('Goodbye, world!') ... Goodbye, world! Traceback (most recent call last): File "<stdin>", li...
python, official-docs, cpython, P0
Local_Trusted_Corpus
600b2763-be62-4c45-8434-25f0c931858e
CPython Docs
file://datasets/cpython/Doc/tutorial/errors.rst
unknown
3d4c648c-7ce3-4a72-a411-a7b59c82fde0
54,027
supabase-export-v2
f42285a18cf20853
it is passed on to outer :keyword:`try` statements; if no handler is found, it is an *unhandled exception* and execution stops with an error message. A :keyword:`try` statement may have more than one *except clause*, to specify handlers for different exceptions. At most one handler will be executed. Handlers only handl...
trusted_official_docs
CPython Docs
it is passed on to outer :keyword:`try` statements; if no handler is found, it is an *unhandled exception* and execution stops with an error message. A :keyword:`try` statement may have more than one *except clause*, to specify handlers for different exceptions. At most one handler will be executed. Handlers only handl...
it is passed on to outer :keyword:`try` statements; if no handler is found, it is an *unhandled exception* and execution stops with an error message. A :keyword:`try` statement may have more than one *except clause*, to specify handlers for different exceptions. At most one handler will be executed. Handlers only handl...
python, official-docs, cpython, P0
Local_Trusted_Corpus
60c3bebd-ea53-436c-90d6-c5978c6c6523
CPython Docs
file://datasets/cpython/Doc/tutorial/errors.rst
unknown
3d4c648c-7ce3-4a72-a411-a7b59c82fde0
54,033
supabase-export-v2
787583ece705aab5
if the *except clauses* were reversed (with ``except B`` first), it would have printed B, B, B --- the first matching *except clause* is triggered. When an exception occurs, it may have associated values, also known as the exception's *arguments*. The presence and types of the arguments depend on the exception type.
trusted_official_docs
CPython Docs
if the *except clauses* were reversed (with ``except B`` first), it would have printed B, B, B --- the first matching *except clause* is triggered. When an exception occurs, it may have associated values, also known as the exception's *arguments*. The presence and types of the arguments depend on the exception type.
if the *except clauses* were reversed (with ``except B`` first), it would have printed B, B, B --- the first matching *except clause* is triggered. When an exception occurs, it may have associated values, also known as the exception's *arguments*. The presence and types of the arguments depend on the exception type.
python, official-docs, cpython, P0
Local_Trusted_Corpus
60c52f8f-adfa-4375-b5b5-9a4899b91672
CPython Docs
file://datasets/cpython/Doc/tutorial/errors.rst
unknown
3d4c648c-7ce3-4a72-a411-a7b59c82fde0
54,104
supabase-export-v2
2448d4502472301b
This is because in practice the exceptions would typically be ones that have already been raised and caught by the program, along the following pattern:: >>> excs = [] ... for test in tests: ... try: ... test.run() ... except Exception as e: ... excs.append(e) ... >>> if excs: ... raise ExceptionGroup("Test Fail...
trusted_official_docs
CPython Docs
This is because in practice the exceptions would typically be ones that have already been raised and caught by the program, along the following pattern:: >>> excs = [] ... for test in tests: ... try: ... test.run() ... except Exception as e: ... excs.append(e) ... >>> if excs: ... raise ExceptionGroup("Test Fail...
This is because in practice the exceptions would typically be ones that have already been raised and caught by the program, along the following pattern:: >>> excs = [] ... for test in tests: ... try: ... test.run() ... except Exception as e: ... excs.append(e) ... >>> if excs: ... raise ExceptionGroup("Test Fail...
python, official-docs, cpython, P0
Local_Trusted_Corpus
6394d35e-1063-4398-9206-49302afa4cd6
CPython Docs
file://datasets/cpython/Doc/tutorial/errors.rst
unknown
3d4c648c-7ce3-4a72-a411-a7b59c82fde0
54,102
supabase-export-v2
81361e12c5a38a28
last): | File "<stdin>", line 2, in <module> | f() | ~^^ | File "<stdin>", line 2, in f | raise ExceptionGroup( | ...<12 lines>... | ) | ExceptionGroup: group1 (1 sub-exception) +-+---------------- 1 ---------------- | ExceptionGroup: group2 (1 sub-exception) +-+---------------- 1 ---------------- | RecursionError...
trusted_official_docs
CPython Docs
last): | File "<stdin>", line 2, in <module> | f() | ~^^ | File "<stdin>", line 2, in f | raise ExceptionGroup( | ...<12 lines>... | ) | ExceptionGroup: group1 (1 sub-exception) +-+---------------- 1 ---------------- | ExceptionGroup: group2 (1 sub-exception) +-+---------------- 1 ---------------- | RecursionError...
last): | File "<stdin>", line 2, in <module> | f() | ~^^ | File "<stdin>", line 2, in f | raise ExceptionGroup( | ...<12 lines>... | ) | ExceptionGroup: group1 (1 sub-exception) +-+---------------- 1 ---------------- | ExceptionGroup: group2 (1 sub-exception) +-+---------------- 1 ---------------- | RecursionError...
python, official-docs, cpython, P0
Local_Trusted_Corpus
67028178-456b-4f91-8cf0-46a1da1f5849
CPython Docs
file://datasets/cpython/Doc/tutorial/errors.rst
unknown
3d4c648c-7ce3-4a72-a411-a7b59c82fde0
54,015
supabase-export-v2
78f0de5973ecca49
built-in exceptions, but need not be true for user-defined exceptions (although it is a useful convention). Standard exception names are built-in identifiers (not reserved keywords). The rest of the line provides detail based on the type of exception and what caused it.
trusted_official_docs
CPython Docs
built-in exceptions, but need not be true for user-defined exceptions (although it is a useful convention). Standard exception names are built-in identifiers (not reserved keywords). The rest of the line provides detail based on the type of exception and what caused it.
built-in exceptions, but need not be true for user-defined exceptions (although it is a useful convention). Standard exception names are built-in identifiers (not reserved keywords). The rest of the line provides detail based on the type of exception and what caused it.
python, official-docs, cpython, P0
Local_Trusted_Corpus
67fe9c1a-44f8-41c0-8ca5-c855fc286875
CPython Docs
file://datasets/cpython/Doc/tutorial/errors.rst
unknown
3d4c648c-7ce3-4a72-a411-a7b59c82fde0
54,100
supabase-export-v2
de98ef96d0527945
2 +------------------------------------ >>> try: ... f() ... except Exception as e: ... print(f'caught {type(e)}: {e}') ... caught <class 'ExceptionGroup'>: there were problems (2 sub-exceptions) >>> By using ``except*`` instead of ``except``, we can selectively handle only the exceptions in the group that match a cert...
trusted_official_docs
CPython Docs
2 +------------------------------------ >>> try: ... f() ... except Exception as e: ... print(f'caught {type(e)}: {e}') ... caught <class 'ExceptionGroup'>: there were problems (2 sub-exceptions) >>> By using ``except*`` instead of ``except``, we can selectively handle only the exceptions in the group that match a cert...
2 +------------------------------------ >>> try: ... f() ... except Exception as e: ... print(f'caught {type(e)}: {e}') ... caught <class 'ExceptionGroup'>: there were problems (2 sub-exceptions) >>> By using ``except*`` instead of ``except``, we can selectively handle only the exceptions in the group that match a cert...
python, official-docs, cpython, P0
Local_Trusted_Corpus
6f8f6212-6ca5-49cb-9891-4503eb4bc396
CPython Docs
file://datasets/cpython/Doc/tutorial/errors.rst
unknown
3d4c648c-7ce3-4a72-a411-a7b59c82fde0
54,038
supabase-export-v2
64044bf502fed81d
the program should terminate. They include :exc:`SystemExit` which is raised by :meth:`sys.exit` and :exc:`KeyboardInterrupt` which is raised when a user wishes to interrupt the program. :exc:`Exception` can be used as a wildcard that catches (almost) everything. However, it is good practice to be as specific as possib...
trusted_official_docs
CPython Docs
the program should terminate. They include :exc:`SystemExit` which is raised by :meth:`sys.exit` and :exc:`KeyboardInterrupt` which is raised when a user wishes to interrupt the program. :exc:`Exception` can be used as a wildcard that catches (almost) everything. However, it is good practice to be as specific as possib...
the program should terminate. They include :exc:`SystemExit` which is raised by :meth:`sys.exit` and :exc:`KeyboardInterrupt` which is raised when a user wishes to interrupt the program. :exc:`Exception` can be used as a wildcard that catches (almost) everything. However, it is good practice to be as specific as possib...
python, official-docs, cpython, P0
Local_Trusted_Corpus
74217bbc-10dc-4c5f-a65b-1f0293eb8e05
CPython Docs
file://datasets/cpython/Doc/tutorial/errors.rst
unknown
3d4c648c-7ce3-4a72-a411-a7b59c82fde0
54,103
supabase-export-v2
14db2e5f8ea2bd4b
| ) | ExceptionGroup: group1 (1 sub-exception) +-+---------------- 1 ---------------- | ExceptionGroup: group2 (1 sub-exception) +-+---------------- 1 ---------------- | RecursionError: 4 +------------------------------------ >>> Note that the exceptions nested in an exception group must be instances, not types. This i...
trusted_official_docs
CPython Docs
| ) | ExceptionGroup: group1 (1 sub-exception) +-+---------------- 1 ---------------- | ExceptionGroup: group2 (1 sub-exception) +-+---------------- 1 ---------------- | RecursionError: 4 +------------------------------------ >>> Note that the exceptions nested in an exception group must be instances, not types. This i...
| ) | ExceptionGroup: group1 (1 sub-exception) +-+---------------- 1 ---------------- | ExceptionGroup: group2 (1 sub-exception) +-+---------------- 1 ---------------- | RecursionError: 4 +------------------------------------ >>> Note that the exceptions nested in an exception group must be instances, not types. This i...
python, official-docs, cpython, P0
Local_Trusted_Corpus
76481a36-b3a0-4fb9-a521-31d31950717e
CPython Docs
file://datasets/cpython/Doc/tutorial/errors.rst
unknown
3d4c648c-7ce3-4a72-a411-a7b59c82fde0
54,111
supabase-export-v2
930360e401c2bb56
excs = [] >>> for i in range(3): ... try: ... f() ... except Exception as e: ... e.add_note(f'Happened in Iteration {i+1}') ... excs.append(e) ... >>> raise ExceptionGroup('We have some problems', excs) + Exception Group Traceback (most recent call last): | File "<stdin>", line 1, in <module> | raise ExceptionGroup(...
trusted_official_docs
CPython Docs
excs = [] >>> for i in range(3): ... try: ... f() ... except Exception as e: ... e.add_note(f'Happened in Iteration {i+1}') ... excs.append(e) ... >>> raise ExceptionGroup('We have some problems', excs) + Exception Group Traceback (most recent call last): | File "<stdin>", line 1, in <module> | raise ExceptionGroup(...
excs = [] >>> for i in range(3): ... try: ... f() ... except Exception as e: ... e.add_note(f'Happened in Iteration {i+1}') ... excs.append(e) ... >>> raise ExceptionGroup('We have some problems', excs) + Exception Group Traceback (most recent call last): | File "<stdin>", line 1, in <module> | raise ExceptionGroup(...
python, official-docs, cpython, P0
Local_Trusted_Corpus
764dd822-2d0d-4d9b-8457-7fb54c3814d4
CPython Docs
file://datasets/cpython/Doc/tutorial/errors.rst
unknown
3d4c648c-7ce3-4a72-a411-a7b59c82fde0
54,010
supabase-export-v2
e7ed76295870a32a
that needs to be fixed. In the example, the error is detected at the function :func:`print`, since a colon (``':'``) is missing just before it. The file name (``<stdin>`` in our example) and line number are printed so you know where to look in case the input came from a file.
trusted_official_docs
CPython Docs
that needs to be fixed. In the example, the error is detected at the function :func:`print`, since a colon (``':'``) is missing just before it. The file name (``<stdin>`` in our example) and line number are printed so you know where to look in case the input came from a file.
that needs to be fixed. In the example, the error is detected at the function :func:`print`, since a colon (``':'``) is missing just before it. The file name (``<stdin>`` in our example) and line number are printed so you know where to look in case the input came from a file.
python, official-docs, cpython, P0
Local_Trusted_Corpus
79e330f6-6b8b-43ca-b936-c8fa5ac1c939
CPython Docs
file://datasets/cpython/Doc/tutorial/errors.rst
unknown
3d4c648c-7ce3-4a72-a411-a7b59c82fde0
54,050
supabase-export-v2
06a987a8488d070e
The :keyword:`raise` statement allows the programmer to force a specified exception to occur. For example:: >>> raise NameError('HiThere') Traceback (most recent call last): File "<stdin>", line 1, in <module> raise NameError('HiThere') NameError: HiThere
trusted_official_docs
CPython Docs
The :keyword:`raise` statement allows the programmer to force a specified exception to occur. For example:: >>> raise NameError('HiThere') Traceback (most recent call last): File "<stdin>", line 1, in <module> raise NameError('HiThere') NameError: HiThere
The :keyword:`raise` statement allows the programmer to force a specified exception to occur. For example:: >>> raise NameError('HiThere') Traceback (most recent call last): File "<stdin>", line 1, in <module> raise NameError('HiThere') NameError: HiThere
python, official-docs, cpython, P0
Local_Trusted_Corpus
7ae21157-8b32-4146-ae9a-f0f0acf1a775
CPython Docs
file://datasets/cpython/Doc/tutorial/errors.rst
unknown
3d4c648c-7ce3-4a72-a411-a7b59c82fde0
54,042
supabase-export-v2
11f4feefdaa980fb
int(s.strip()) except OSError as err: print("OS error:", err) except ValueError: print("Could not convert data to an integer.") except Exception as err: print(f"Unexpected {err=}, {type(err)=}") raise The :keyword:`try` ... :keyword:`except` statement has an optional *else clause*, which, when present, must follow all ...
trusted_official_docs
CPython Docs
int(s.strip()) except OSError as err: print("OS error:", err) except ValueError: print("Could not convert data to an integer.") except Exception as err: print(f"Unexpected {err=}, {type(err)=}") raise The :keyword:`try` ... :keyword:`except` statement has an optional *else clause*, which, when present, must follow all ...
int(s.strip()) except OSError as err: print("OS error:", err) except ValueError: print("Could not convert data to an integer.") except Exception as err: print(f"Unexpected {err=}, {type(err)=}") raise The :keyword:`try` ... :keyword:`except` statement has an optional *else clause*, which, when present, must follow all ...
python, official-docs, cpython, P0
Local_Trusted_Corpus
8948a342-b59a-4151-abf8-7a60b180f438
CPython Docs
file://datasets/cpython/Doc/tutorial/errors.rst
unknown
3d4c648c-7ce3-4a72-a411-a7b59c82fde0
54,037
supabase-export-v2
df1c157a09bdc6ce
The exception's :meth:`~object.__str__` output is printed as the last part ('detail') of the message for unhandled exceptions. :exc:`BaseException` is the common base class of all exceptions. One of its subclasses, :exc:`Exception`, is the base class of all the non-fatal exceptions. Exceptions which are not subclasses ...
trusted_official_docs
CPython Docs
The exception's :meth:`~object.__str__` output is printed as the last part ('detail') of the message for unhandled exceptions. :exc:`BaseException` is the common base class of all exceptions. One of its subclasses, :exc:`Exception`, is the base class of all the non-fatal exceptions. Exceptions which are not subclasses ...
The exception's :meth:`~object.__str__` output is printed as the last part ('detail') of the message for unhandled exceptions. :exc:`BaseException` is the common base class of all exceptions. One of its subclasses, :exc:`Exception`, is the base class of all the non-fatal exceptions. Exceptions which are not subclasses ...
python, official-docs, cpython, P0
Local_Trusted_Corpus
8c241cbe-e8da-4e50-9aca-5bc8c0c8e959
CPython Docs
file://datasets/cpython/Doc/tutorial/errors.rst
unknown
3d4c648c-7ce3-4a72-a411-a7b59c82fde0
54,068
supabase-export-v2
6eb919ff6ab54006
User-defined Exceptions ======================= Programs may name their own exceptions by creating a new exception class (see :ref:`tut-classes` for more about Python classes). Exceptions should typically be derived from the :exc:`Exception` class, either directly or indirectly.
trusted_official_docs
CPython Docs
User-defined Exceptions ======================= Programs may name their own exceptions by creating a new exception class (see :ref:`tut-classes` for more about Python classes). Exceptions should typically be derived from the :exc:`Exception` class, either directly or indirectly.
User-defined Exceptions ======================= Programs may name their own exceptions by creating a new exception class (see :ref:`tut-classes` for more about Python classes). Exceptions should typically be derived from the :exc:`Exception` class, either directly or indirectly.
python, official-docs, cpython, P0
Local_Trusted_Corpus
8eb78a95-c505-48f7-99aa-b5f0eec54939
CPython Docs
file://datasets/cpython/Doc/tutorial/errors.rst
unknown
3d4c648c-7ce3-4a72-a411-a7b59c82fde0
54,093
supabase-export-v2
8c24956020d862b8
applications. The :keyword:`with` statement allows objects like files to be used in a way that ensures they are always cleaned up promptly and correctly. :: with open("myfile.txt") as f: for line in f: print(line, end="")
trusted_official_docs
CPython Docs
applications. The :keyword:`with` statement allows objects like files to be used in a way that ensures they are always cleaned up promptly and correctly. :: with open("myfile.txt") as f: for line in f: print(line, end="")
applications. The :keyword:`with` statement allows objects like files to be used in a way that ensures they are always cleaned up promptly and correctly. :: with open("myfile.txt") as f: for line in f: print(line, end="")
python, official-docs, cpython, P0
Local_Trusted_Corpus
8f9f648e-7019-4234-a51a-1aee81a27143
CPython Docs
file://datasets/cpython/Doc/tutorial/errors.rst
unknown
3d4c648c-7ce3-4a72-a411-a7b59c82fde0
54,017
supabase-export-v2
c0f73c9396b2eda4
form of a stack traceback. In general it contains a stack traceback listing source lines; however, it will not display lines read from standard input. :ref:`bltin-exceptions` lists the built-in exceptions and their meanings.
trusted_official_docs
CPython Docs
form of a stack traceback. In general it contains a stack traceback listing source lines; however, it will not display lines read from standard input. :ref:`bltin-exceptions` lists the built-in exceptions and their meanings.
form of a stack traceback. In general it contains a stack traceback listing source lines; however, it will not display lines read from standard input. :ref:`bltin-exceptions` lists the built-in exceptions and their meanings.
python, official-docs, cpython, P0
Local_Trusted_Corpus
93eafbd3-a004-49b7-9008-f5bf74bb4529
CPython Docs
file://datasets/cpython/Doc/tutorial/errors.rst
unknown
3d4c648c-7ce3-4a72-a411-a7b59c82fde0
54,046
supabase-export-v2
f3d520207830af6d
that occur immediately in the *try clause*, but also those that occur inside functions that are called (even indirectly) in the *try clause*. For example:: >>> def this_fails(): ... x = 1/0 ... >>> try: ... this_fails() ... except ZeroDivisionError as err: ... print('Handling run-time error:', err) ... Handling r...
trusted_official_docs
CPython Docs
that occur immediately in the *try clause*, but also those that occur inside functions that are called (even indirectly) in the *try clause*. For example:: >>> def this_fails(): ... x = 1/0 ... >>> try: ... this_fails() ... except ZeroDivisionError as err: ... print('Handling run-time error:', err) ... Handling r...
that occur immediately in the *try clause*, but also those that occur inside functions that are called (even indirectly) in the *try clause*. For example:: >>> def this_fails(): ... x = 1/0 ... >>> try: ... this_fails() ... except ZeroDivisionError as err: ... print('Handling run-time error:', err) ... Handling r...
python, official-docs, cpython, P0
Local_Trusted_Corpus
9795e19c-a082-4da3-a187-9e99496b629e
CPython Docs
file://datasets/cpython/Doc/tutorial/errors.rst
unknown
3d4c648c-7ce3-4a72-a411-a7b59c82fde0
54,054
supabase-export-v2
676b2315da79118e
determine whether an exception was raised but don't intend to handle it, a simpler form of the :keyword:`raise` statement allows you to re-raise the exception:: >>> try: ... raise NameError('HiThere') ... except NameError: ... print('An exception flew by!') ... raise ... An exception flew by! Traceback (most recen...
trusted_official_docs
CPython Docs
determine whether an exception was raised but don't intend to handle it, a simpler form of the :keyword:`raise` statement allows you to re-raise the exception:: >>> try: ... raise NameError('HiThere') ... except NameError: ... print('An exception flew by!') ... raise ... An exception flew by! Traceback (most recen...
determine whether an exception was raised but don't intend to handle it, a simpler form of the :keyword:`raise` statement allows you to re-raise the exception:: >>> try: ... raise NameError('HiThere') ... except NameError: ... print('An exception flew by!') ... raise ... An exception flew by! Traceback (most recen...
python, official-docs, cpython, P0
Local_Trusted_Corpus
98415256-80b6-4add-bb31-53a6a4d8df62
CPython Docs
file://datasets/cpython/Doc/tutorial/errors.rst
unknown
3d4c648c-7ce3-4a72-a411-a7b59c82fde0
54,094
supabase-export-v2
a9b94c6925b36492
with open("myfile.txt") as f: for line in f: print(line, end="") After the statement is executed, the file *f* is always closed, even if a problem was encountered while processing the lines. Objects which, like files, provide predefined clean-up actions will indicate this in their documentation.
trusted_official_docs
CPython Docs
with open("myfile.txt") as f: for line in f: print(line, end="") After the statement is executed, the file *f* is always closed, even if a problem was encountered while processing the lines. Objects which, like files, provide predefined clean-up actions will indicate this in their documentation.
with open("myfile.txt") as f: for line in f: print(line, end="") After the statement is executed, the file *f* is always closed, even if a problem was encountered while processing the lines. Objects which, like files, provide predefined clean-up actions will indicate this in their documentation.
python, official-docs, cpython, P0
Local_Trusted_Corpus
9b21a100-ad4b-4068-a48c-1a12dcb26ccb
CPython Docs
file://datasets/cpython/Doc/tutorial/errors.rst
unknown
3d4c648c-7ce3-4a72-a411-a7b59c82fde0
54,005
supabase-export-v2
ad5f8ae6d8d5fb40
********************* Errors and Exceptions ********************* Until now error messages haven't been more than mentioned, but if you have tried out the examples you have probably seen some. There are (at least) two distinguishable kinds of errors: *syntax errors* and *exceptions*.
trusted_official_docs
CPython Docs
********************* Errors and Exceptions ********************* Until now error messages haven't been more than mentioned, but if you have tried out the examples you have probably seen some. There are (at least) two distinguishable kinds of errors: *syntax errors* and *exceptions*.
********************* Errors and Exceptions ********************* Until now error messages haven't been more than mentioned, but if you have tried out the examples you have probably seen some. There are (at least) two distinguishable kinds of errors: *syntax errors* and *exceptions*.
python, official-docs, cpython, P0
Local_Trusted_Corpus
9e05c06f-3d1b-4288-a003-fba3c0fb33fe
CPython Docs
file://datasets/cpython/Doc/tutorial/errors.rst
unknown
3d4c648c-7ce3-4a72-a411-a7b59c82fde0
54,059
supabase-export-v2
a5bd05f9882eb0e6
another exception occurred: <BLANKLINE> Traceback (most recent call last): File "<stdin>", line 4, in <module> raise RuntimeError("unable to handle error") RuntimeError: unable to handle error To indicate that an exception is a direct consequence of another, the :keyword:`raise` statement allows an optional :keyword:`f...
trusted_official_docs
CPython Docs
another exception occurred: <BLANKLINE> Traceback (most recent call last): File "<stdin>", line 4, in <module> raise RuntimeError("unable to handle error") RuntimeError: unable to handle error To indicate that an exception is a direct consequence of another, the :keyword:`raise` statement allows an optional :keyword:`f...
another exception occurred: <BLANKLINE> Traceback (most recent call last): File "<stdin>", line 4, in <module> raise RuntimeError("unable to handle error") RuntimeError: unable to handle error To indicate that an exception is a direct consequence of another, the :keyword:`raise` statement allows an optional :keyword:`f...
python, official-docs, cpython, P0
Local_Trusted_Corpus
a59aae00-f9ec-41e9-ab6e-9f5fd45fb9c1
CPython Docs
file://datasets/cpython/Doc/tutorial/errors.rst
unknown
3d4c648c-7ce3-4a72-a411-a7b59c82fde0
54,076
supabase-export-v2
730231db021e549b
... raise KeyboardInterrupt ... finally: ... print('Goodbye, world!') ... Goodbye, world! Traceback (most recent call last): File "<stdin>", line 2, in <module> raise KeyboardInterrupt KeyboardInterrupt If a :keyword:`finally` clause is present, the :keyword:`!finally` clause will execute as the last task before the :k...
trusted_official_docs
CPython Docs
... raise KeyboardInterrupt ... finally: ... print('Goodbye, world!') ... Goodbye, world! Traceback (most recent call last): File "<stdin>", line 2, in <module> raise KeyboardInterrupt KeyboardInterrupt If a :keyword:`finally` clause is present, the :keyword:`!finally` clause will execute as the last task before the :k...
... raise KeyboardInterrupt ... finally: ... print('Goodbye, world!') ... Goodbye, world! Traceback (most recent call last): File "<stdin>", line 2, in <module> raise KeyboardInterrupt KeyboardInterrupt If a :keyword:`finally` clause is present, the :keyword:`!finally` clause will execute as the last task before the :k...
python, official-docs, cpython, P0
Local_Trusted_Corpus
a646aa4d-6158-4f05-88c9-948000f9d4f3
CPython Docs
file://datasets/cpython/Doc/tutorial/errors.rst
unknown
3d4c648c-7ce3-4a72-a411-a7b59c82fde0
54,051
supabase-export-v2
a047f00cc1e987db
>>> raise NameError('HiThere') Traceback (most recent call last): File "<stdin>", line 1, in <module> raise NameError('HiThere') NameError: HiThere The sole argument to :keyword:`raise` indicates the exception to be raised. This must be either an exception instance or an exception class (a class that derives from :clas...
trusted_official_docs
CPython Docs
>>> raise NameError('HiThere') Traceback (most recent call last): File "<stdin>", line 1, in <module> raise NameError('HiThere') NameError: HiThere The sole argument to :keyword:`raise` indicates the exception to be raised. This must be either an exception instance or an exception class (a class that derives from :clas...
>>> raise NameError('HiThere') Traceback (most recent call last): File "<stdin>", line 1, in <module> raise NameError('HiThere') NameError: HiThere The sole argument to :keyword:`raise` indicates the exception to be raised. This must be either an exception instance or an exception class (a class that derives from :clas...
python, official-docs, cpython, P0
Local_Trusted_Corpus
ad55ae14-d956-4202-bf66-321a1988c1fd
CPython Docs
file://datasets/cpython/Doc/tutorial/errors.rst
unknown
3d4c648c-7ce3-4a72-a411-a7b59c82fde0
54,026
supabase-export-v2
d1f61d46ff28b4f7
Then, if its type matches the exception named after the :keyword:`except` keyword, the *except clause* is executed, and then execution continues after the try/except block. * If an exception occurs which does not match the exception named in the *except clause*, it is passed on to outer :keyword:`try` statements; if n...
trusted_official_docs
CPython Docs
Then, if its type matches the exception named after the :keyword:`except` keyword, the *except clause* is executed, and then execution continues after the try/except block. * If an exception occurs which does not match the exception named in the *except clause*, it is passed on to outer :keyword:`try` statements; if n...
Then, if its type matches the exception named after the :keyword:`except` keyword, the *except clause* is executed, and then execution continues after the try/except block. * If an exception occurs which does not match the exception named in the *except clause*, it is passed on to outer :keyword:`try` statements; if n...
python, official-docs, cpython, P0
Local_Trusted_Corpus
b19509df-c166-4e93-8ca1-8738f48d0da8
CPython Docs
file://datasets/cpython/Doc/tutorial/errors.rst
unknown
3d4c648c-7ce3-4a72-a411-a7b59c82fde0
54,071
supabase-export-v2
398f6ec0f7d0a7c9
Most exceptions are defined with names that end in "Error", similar to the naming of the standard exceptions. Many standard modules define their own exceptions to report errors that may occur in functions they define.
trusted_official_docs
CPython Docs
Most exceptions are defined with names that end in "Error", similar to the naming of the standard exceptions. Many standard modules define their own exceptions to report errors that may occur in functions they define.
Most exceptions are defined with names that end in "Error", similar to the naming of the standard exceptions. Many standard modules define their own exceptions to report errors that may occur in functions they define.
python, official-docs, cpython, P0
Local_Trusted_Corpus
b7039adb-5b43-462c-95ce-1c0a69e26010
CPython Docs
file://datasets/cpython/Doc/tutorial/errors.rst
unknown
3d4c648c-7ce3-4a72-a411-a7b59c82fde0
54,090
supabase-export-v2
923b1b8f4db946ee
Predefined Clean-up Actions =========================== Some objects define standard clean-up actions to be undertaken when the object is no longer needed, regardless of whether or not the operation using the object succeeded or failed. Look at the following example, which tries to open a file and print its contents to...
trusted_official_docs
CPython Docs
Predefined Clean-up Actions =========================== Some objects define standard clean-up actions to be undertaken when the object is no longer needed, regardless of whether or not the operation using the object succeeded or failed. Look at the following example, which tries to open a file and print its contents to...
Predefined Clean-up Actions =========================== Some objects define standard clean-up actions to be undertaken when the object is no longer needed, regardless of whether or not the operation using the object succeeded or failed. Look at the following example, which tries to open a file and print its contents to...
python, official-docs, cpython, P0
Local_Trusted_Corpus
c18ee171-8942-4428-a719-49d3000a45c3
CPython Docs
file://datasets/cpython/Doc/tutorial/errors.rst
unknown
3d4c648c-7ce3-4a72-a411-a7b59c82fde0
54,070
supabase-export-v2
74e333fdf10bd365
are usually kept simple, often only offering a number of attributes that allow information about the error to be extracted by handlers for the exception. Most exceptions are defined with names that end in "Error", similar to the naming of the standard exceptions.
trusted_official_docs
CPython Docs
are usually kept simple, often only offering a number of attributes that allow information about the error to be extracted by handlers for the exception. Most exceptions are defined with names that end in "Error", similar to the naming of the standard exceptions.
are usually kept simple, often only offering a number of attributes that allow information about the error to be extracted by handlers for the exception. Most exceptions are defined with names that end in "Error", similar to the naming of the standard exceptions.
python, official-docs, cpython, P0
Local_Trusted_Corpus
c2330f23-76e3-483c-9498-80cef6a7f5c4
CPython Docs
file://datasets/cpython/Doc/tutorial/errors.rst
unknown
3d4c648c-7ce3-4a72-a411-a7b59c82fde0
54,043
supabase-export-v2
a607561ea45a856d
must follow all *except clauses*. It is useful for code that must be executed if the *try clause* does not raise an exception. For example:: for arg in sys.argv[1:]: try: f = open(arg, 'r') except OSError: print('cannot open', arg) else: print(arg, 'has', len(f.readlines()), 'lines') f.close()
trusted_official_docs
CPython Docs
must follow all *except clauses*. It is useful for code that must be executed if the *try clause* does not raise an exception. For example:: for arg in sys.argv[1:]: try: f = open(arg, 'r') except OSError: print('cannot open', arg) else: print(arg, 'has', len(f.readlines()), 'lines') f.close()
must follow all *except clauses*. It is useful for code that must be executed if the *try clause* does not raise an exception. For example:: for arg in sys.argv[1:]: try: f = open(arg, 'r') except OSError: print('cannot open', arg) else: print(arg, 'has', len(f.readlines()), 'lines') f.close()
python, official-docs, cpython, P0
Local_Trusted_Corpus
d09ce365-febd-4ab3-9036-69eb08f7f1e3
CPython Docs
file://datasets/cpython/Doc/tutorial/errors.rst
unknown
3d4c648c-7ce3-4a72-a411-a7b59c82fde0
54,087
supabase-export-v2
082a18cfe1aca49a
event. The :exc:`TypeError` raised by dividing two strings is not handled by the :keyword:`except` clause and therefore re-raised after the :keyword:`!finally` clause has been executed. In real world applications, the :keyword:`finally` clause is useful for releasing external resources (such as files or network connect...
trusted_official_docs
CPython Docs
event. The :exc:`TypeError` raised by dividing two strings is not handled by the :keyword:`except` clause and therefore re-raised after the :keyword:`!finally` clause has been executed. In real world applications, the :keyword:`finally` clause is useful for releasing external resources (such as files or network connect...
event. The :exc:`TypeError` raised by dividing two strings is not handled by the :keyword:`except` clause and therefore re-raised after the :keyword:`!finally` clause has been executed. In real world applications, the :keyword:`finally` clause is useful for releasing external resources (such as files or network connect...
python, official-docs, cpython, P0
Local_Trusted_Corpus
d0cfe040-15e1-4411-bfa3-a237121aaf9f
CPython Docs
file://datasets/cpython/Doc/tutorial/errors.rst
unknown
3d4c648c-7ce3-4a72-a411-a7b59c82fde0
54,077
supabase-export-v2
fb1a505a0a878e4f
completes. The :keyword:`!finally` clause runs whether or not the :keyword:`!try` statement produces an exception. The following points discuss more complex cases when an exception occurs: * If an exception occurs during execution of the :keyword:`!try` clause, the exception may be handled by an :keyword:`except` cla...
trusted_official_docs
CPython Docs
completes. The :keyword:`!finally` clause runs whether or not the :keyword:`!try` statement produces an exception. The following points discuss more complex cases when an exception occurs: * If an exception occurs during execution of the :keyword:`!try` clause, the exception may be handled by an :keyword:`except` cla...
completes. The :keyword:`!finally` clause runs whether or not the :keyword:`!try` statement produces an exception. The following points discuss more complex cases when an exception occurs: * If an exception occurs during execution of the :keyword:`!try` clause, the exception may be handled by an :keyword:`except` cla...
python, official-docs, cpython, P0
Local_Trusted_Corpus
d2b539cc-9fd0-42b9-9b58-da2d30b747d0
CPython Docs
file://datasets/cpython/Doc/tutorial/errors.rst
unknown
3d4c648c-7ce3-4a72-a411-a7b59c82fde0
54,034
supabase-export-v2
34d647042eeccaf2
exception occurs, it may have associated values, also known as the exception's *arguments*. The presence and types of the arguments depend on the exception type. The *except clause* may specify a variable after the exception name. The variable is bound to the exception instance which typically has an ``args`` attribute...
trusted_official_docs
CPython Docs
exception occurs, it may have associated values, also known as the exception's *arguments*. The presence and types of the arguments depend on the exception type. The *except clause* may specify a variable after the exception name. The variable is bound to the exception instance which typically has an ``args`` attribute...
exception occurs, it may have associated values, also known as the exception's *arguments*. The presence and types of the arguments depend on the exception type. The *except clause* may specify a variable after the exception name. The variable is bound to the exception instance which typically has an ``args`` attribute...
python, official-docs, cpython, P0
Local_Trusted_Corpus
d300169d-6399-4492-9a48-130d1abc728b
CPython Docs
file://datasets/cpython/Doc/tutorial/errors.rst
unknown
3d4c648c-7ce3-4a72-a411-a7b59c82fde0
54,064
supabase-export-v2
b46d3b360e793031
It also allows disabling automatic exception chaining using the ``from None`` idiom:: >>> try: ... open('database.sqlite') ... except OSError: ... raise RuntimeError from None ... Traceback (most recent call last): File "<stdin>", line 4, in <module> raise RuntimeError from None RuntimeError
trusted_official_docs
CPython Docs
It also allows disabling automatic exception chaining using the ``from None`` idiom:: >>> try: ... open('database.sqlite') ... except OSError: ... raise RuntimeError from None ... Traceback (most recent call last): File "<stdin>", line 4, in <module> raise RuntimeError from None RuntimeError
It also allows disabling automatic exception chaining using the ``from None`` idiom:: >>> try: ... open('database.sqlite') ... except OSError: ... raise RuntimeError from None ... Traceback (most recent call last): File "<stdin>", line 4, in <module> raise RuntimeError from None RuntimeError
python, official-docs, cpython, P0
Local_Trusted_Corpus
d71f11f4-11bb-463c-bcac-8b0a15e35cbf
CPython Docs
file://datasets/cpython/Doc/tutorial/errors.rst
unknown
3d4c648c-7ce3-4a72-a411-a7b59c82fde0
54,086
supabase-export-v2
acf58f0dedd280e6
<module> divide("2", "1") ~~~~~~^^^^^^^^^^ File "<stdin>", line 3, in divide result = x / y ~~^~~ TypeError: unsupported operand type(s) for /: 'str' and 'str' As you can see, the :keyword:`finally` clause is executed in any event. The :exc:`TypeError` raised by dividing two strings is not handled by the :keyword:`exce...
trusted_official_docs
CPython Docs
<module> divide("2", "1") ~~~~~~^^^^^^^^^^ File "<stdin>", line 3, in divide result = x / y ~~^~~ TypeError: unsupported operand type(s) for /: 'str' and 'str' As you can see, the :keyword:`finally` clause is executed in any event. The :exc:`TypeError` raised by dividing two strings is not handled by the :keyword:`exce...
<module> divide("2", "1") ~~~~~~^^^^^^^^^^ File "<stdin>", line 3, in divide result = x / y ~~^~~ TypeError: unsupported operand type(s) for /: 'str' and 'str' As you can see, the :keyword:`finally` clause is executed in any event. The :exc:`TypeError` raised by dividing two strings is not handled by the :keyword:`exce...
python, official-docs, cpython, P0
Local_Trusted_Corpus
d743f668-36e7-43c5-a55a-557ba770efe7
CPython Docs
file://datasets/cpython/Doc/tutorial/errors.rst
unknown
3d4c648c-7ce3-4a72-a411-a7b59c82fde0
54,016
supabase-export-v2
8181162f23c408d7
The rest of the line provides detail based on the type of exception and what caused it. The preceding part of the error message shows the context where the exception occurred, in the form of a stack traceback. In general it contains a stack traceback listing source lines; however, it will not display lines read from st...
trusted_official_docs
CPython Docs
The rest of the line provides detail based on the type of exception and what caused it. The preceding part of the error message shows the context where the exception occurred, in the form of a stack traceback. In general it contains a stack traceback listing source lines; however, it will not display lines read from st...
The rest of the line provides detail based on the type of exception and what caused it. The preceding part of the error message shows the context where the exception occurred, in the form of a stack traceback. In general it contains a stack traceback listing source lines; however, it will not display lines read from st...
python, official-docs, cpython, P0
Local_Trusted_Corpus
d746023f-9aa3-4328-9b41-65974f970f4d
CPython Docs
file://datasets/cpython/Doc/tutorial/errors.rst
unknown
3d4c648c-7ce3-4a72-a411-a7b59c82fde0
54,045
supabase-export-v2
f74733d6d015a54f
to the :keyword:`try` clause because it avoids accidentally catching an exception that wasn't raised by the code being protected by the :keyword:`!try` ... :keyword:`!except` statement. Exception handlers do not handle only exceptions that occur immediately in the *try clause*, but also those that occur inside function...
trusted_official_docs
CPython Docs
to the :keyword:`try` clause because it avoids accidentally catching an exception that wasn't raised by the code being protected by the :keyword:`!try` ... :keyword:`!except` statement. Exception handlers do not handle only exceptions that occur immediately in the *try clause*, but also those that occur inside function...
to the :keyword:`try` clause because it avoids accidentally catching an exception that wasn't raised by the code being protected by the :keyword:`!try` ... :keyword:`!except` statement. Exception handlers do not handle only exceptions that occur immediately in the *try clause*, but also those that occur inside function...
python, official-docs, cpython, P0
Local_Trusted_Corpus
deffd215-80f8-4843-ad74-7607bcc7c6f2
CPython Docs
file://datasets/cpython/Doc/tutorial/errors.rst
unknown
3d4c648c-7ce3-4a72-a411-a7b59c82fde0
54,098
supabase-export-v2
7da93f660d517887
parallel, but there are also other use cases where it is desirable to continue execution and collect multiple errors rather than raise the first exception. The builtin :exc:`ExceptionGroup` wraps a list of exception instances so that they can be raised together. It is an exception itself, so it can be caught like any o...
trusted_official_docs
CPython Docs
parallel, but there are also other use cases where it is desirable to continue execution and collect multiple errors rather than raise the first exception. The builtin :exc:`ExceptionGroup` wraps a list of exception instances so that they can be raised together. It is an exception itself, so it can be caught like any o...
parallel, but there are also other use cases where it is desirable to continue execution and collect multiple errors rather than raise the first exception. The builtin :exc:`ExceptionGroup` wraps a list of exception instances so that they can be raised together. It is an exception itself, so it can be caught like any o...
python, official-docs, cpython, P0
Local_Trusted_Corpus
df46c03b-4e5b-4546-9ad0-3a5d1e20f7b0
CPython Docs
file://datasets/cpython/Doc/tutorial/errors.rst
unknown
3d4c648c-7ce3-4a72-a411-a7b59c82fde0
54,110
supabase-export-v2
8a5b1b3eb4f9f2d1
add context information for the individual errors. In the following each exception in the group has a note indicating when this error has occurred. :: >>> def f(): ... raise OSError('operation failed') ... >>> excs = [] >>> for i in range(3): ... try: ... f() ... except Exception as e: ... e.add_note(f'Happened ...
trusted_official_docs
CPython Docs
add context information for the individual errors. In the following each exception in the group has a note indicating when this error has occurred. :: >>> def f(): ... raise OSError('operation failed') ... >>> excs = [] >>> for i in range(3): ... try: ... f() ... except Exception as e: ... e.add_note(f'Happened ...
add context information for the individual errors. In the following each exception in the group has a note indicating when this error has occurred. :: >>> def f(): ... raise OSError('operation failed') ... >>> excs = [] >>> for i in range(3): ... try: ... f() ... except Exception as e: ... e.add_note(f'Happened ...
python, official-docs, cpython, P0
Local_Trusted_Corpus
df8e577d-ad1d-4537-9aa0-e584858caac5
CPython Docs
file://datasets/cpython/Doc/tutorial/errors.rst
unknown
3d4c648c-7ce3-4a72-a411-a7b59c82fde0
54,029
supabase-export-v2
f18e3eb9a2feb2e4
... except RuntimeError, TypeError, NameError: ... pass A class in an :keyword:`except` clause matches exceptions which are instances of the class itself or one of its derived classes (but not the other way around --- an *except clause* listing a derived class does not match instances of its base classes). For example,...
trusted_official_docs
CPython Docs
... except RuntimeError, TypeError, NameError: ... pass A class in an :keyword:`except` clause matches exceptions which are instances of the class itself or one of its derived classes (but not the other way around --- an *except clause* listing a derived class does not match instances of its base classes). For example,...
... except RuntimeError, TypeError, NameError: ... pass A class in an :keyword:`except` clause matches exceptions which are instances of the class itself or one of its derived classes (but not the other way around --- an *except clause* listing a derived class does not match instances of its base classes). For example,...
python, official-docs, cpython, P0
Local_Trusted_Corpus
e126e0ad-d5a1-4ddb-9508-3f416167af59
CPython Docs
file://datasets/cpython/Doc/tutorial/errors.rst
unknown
3d4c648c-7ce3-4a72-a411-a7b59c82fde0
54,079
supabase-export-v2
d663a22886b6adff
* An exception could occur during execution of an :keyword:`!except` or :keyword:`!else` clause. Again, the exception is re-raised after the :keyword:`!finally` clause has been executed. * If the :keyword:`!finally` clause executes a :keyword:`break`, :keyword:`continue` or :keyword:`return` statement, exceptions are ...
trusted_official_docs
CPython Docs
* An exception could occur during execution of an :keyword:`!except` or :keyword:`!else` clause. Again, the exception is re-raised after the :keyword:`!finally` clause has been executed. * If the :keyword:`!finally` clause executes a :keyword:`break`, :keyword:`continue` or :keyword:`return` statement, exceptions are ...
* An exception could occur during execution of an :keyword:`!except` or :keyword:`!else` clause. Again, the exception is re-raised after the :keyword:`!finally` clause has been executed. * If the :keyword:`!finally` clause executes a :keyword:`break`, :keyword:`continue` or :keyword:`return` statement, exceptions are ...
python, official-docs, cpython, P0
Local_Trusted_Corpus
e16a951b-a9a7-43a1-ae52-ecccf1fd56a2
CPython Docs
file://datasets/cpython/Doc/tutorial/errors.rst
unknown
3d4c648c-7ce3-4a72-a411-a7b59c82fde0
54,053
supabase-export-v2
9b14526f1894c1b2
raise ValueError # shorthand for 'raise ValueError()' If you need to determine whether an exception was raised but don't intend to handle it, a simpler form of the :keyword:`raise` statement allows you to re-raise the exception::
trusted_official_docs
CPython Docs
raise ValueError # shorthand for 'raise ValueError()' If you need to determine whether an exception was raised but don't intend to handle it, a simpler form of the :keyword:`raise` statement allows you to re-raise the exception::
raise ValueError # shorthand for 'raise ValueError()' If you need to determine whether an exception was raised but don't intend to handle it, a simpler form of the :keyword:`raise` statement allows you to re-raise the exception::
python, official-docs, cpython, P0
Local_Trusted_Corpus
e2bd30f5-babd-4898-a93e-1b6f8b1c3992
CPython Docs
file://datasets/cpython/Doc/tutorial/errors.rst
unknown
3d4c648c-7ce3-4a72-a411-a7b59c82fde0
54,058
supabase-export-v2
5a2c2ae60b558b90
If an unhandled exception occurs inside an :keyword:`except` section, it will have the exception being handled attached to it and included in the error message:: >>> try: ... open("database.sqlite") ... except OSError: ... raise RuntimeError("unable to handle error") ... Traceback (most recent call last): File "<s...
trusted_official_docs
CPython Docs
If an unhandled exception occurs inside an :keyword:`except` section, it will have the exception being handled attached to it and included in the error message:: >>> try: ... open("database.sqlite") ... except OSError: ... raise RuntimeError("unable to handle error") ... Traceback (most recent call last): File "<s...
If an unhandled exception occurs inside an :keyword:`except` section, it will have the exception being handled attached to it and included in the error message:: >>> try: ... open("database.sqlite") ... except OSError: ... raise RuntimeError("unable to handle error") ... Traceback (most recent call last): File "<s...
python, official-docs, cpython, P0
Local_Trusted_Corpus
e4e78a65-feb4-49e4-a32e-3006df5b569e
CPython Docs
file://datasets/cpython/Doc/tutorial/errors.rst
unknown
3d4c648c-7ce3-4a72-a411-a7b59c82fde0
54,013
supabase-export-v2
a816032523c9f695
soon learn how to handle them in Python programs. Most exceptions are not handled by programs, however, and result in error messages as shown here:: >>> 10 * (1/0) Traceback (most recent call last): File "<stdin>", line 1, in <module> 10 * (1/0) ~^~ ZeroDivisionError: division by zero >>> 4 + spam*3 Traceback (m...
trusted_official_docs
CPython Docs
soon learn how to handle them in Python programs. Most exceptions are not handled by programs, however, and result in error messages as shown here:: >>> 10 * (1/0) Traceback (most recent call last): File "<stdin>", line 1, in <module> 10 * (1/0) ~^~ ZeroDivisionError: division by zero >>> 4 + spam*3 Traceback (m...
soon learn how to handle them in Python programs. Most exceptions are not handled by programs, however, and result in error messages as shown here:: >>> 10 * (1/0) Traceback (most recent call last): File "<stdin>", line 1, in <module> 10 * (1/0) ~^~ ZeroDivisionError: division by zero >>> 4 + spam*3 Traceback (m...
python, official-docs, cpython, P0
Local_Trusted_Corpus
e5e3cce1-de83-4d2a-80ba-f42127a46086
CPython Docs
file://datasets/cpython/Doc/tutorial/errors.rst
unknown
3d4c648c-7ce3-4a72-a411-a7b59c82fde0
54,091
supabase-export-v2
599aee218d78d0c5
using the object succeeded or failed. Look at the following example, which tries to open a file and print its contents to the screen. :: for line in open("myfile.txt"): print(line, end="")
trusted_official_docs
CPython Docs
using the object succeeded or failed. Look at the following example, which tries to open a file and print its contents to the screen. :: for line in open("myfile.txt"): print(line, end="")
using the object succeeded or failed. Look at the following example, which tries to open a file and print its contents to the screen. :: for line in open("myfile.txt"): print(line, end="")
python, official-docs, cpython, P0
Local_Trusted_Corpus
e969790c-7ba6-4d9a-b8c8-30cdf78a3806
CPython Docs
file://datasets/cpython/Doc/tutorial/errors.rst
unknown
3d4c648c-7ce3-4a72-a411-a7b59c82fde0
54,041
supabase-export-v2
2a631d502f715a9d
import sys try: f = open('myfile.txt') s = f.readline() i = int(s.strip()) except OSError as err: print("OS error:", err) except ValueError: print("Could not convert data to an integer.") except Exception as err: print(f"Unexpected {err=}, {type(err)=}") raise
trusted_official_docs
CPython Docs
import sys try: f = open('myfile.txt') s = f.readline() i = int(s.strip()) except OSError as err: print("OS error:", err) except ValueError: print("Could not convert data to an integer.") except Exception as err: print(f"Unexpected {err=}, {type(err)=}") raise
import sys try: f = open('myfile.txt') s = f.readline() i = int(s.strip()) except OSError as err: print("OS error:", err) except ValueError: print("Could not convert data to an integer.") except Exception as err: print(f"Unexpected {err=}, {type(err)=}") raise
python, official-docs, cpython, P0
Local_Trusted_Corpus
eb3c207f-99e6-4fac-bbaf-191e32e65ceb
CPython Docs
file://datasets/cpython/Doc/tutorial/errors.rst
unknown
3d4c648c-7ce3-4a72-a411-a7b59c82fde0
54,081
supabase-export-v2
d74e790ac45260a2
the :keyword:`!try` statement reaches a :keyword:`break`, :keyword:`continue` or :keyword:`return` statement, the :keyword:`!finally` clause will execute just prior to the :keyword:`!break`, :keyword:`!continue` or :keyword:`!return` statement's execution. * If a :keyword:`!finally` clause includes a :keyword:`!return`...
trusted_official_docs
CPython Docs
the :keyword:`!try` statement reaches a :keyword:`break`, :keyword:`continue` or :keyword:`return` statement, the :keyword:`!finally` clause will execute just prior to the :keyword:`!break`, :keyword:`!continue` or :keyword:`!return` statement's execution. * If a :keyword:`!finally` clause includes a :keyword:`!return`...
the :keyword:`!try` statement reaches a :keyword:`break`, :keyword:`continue` or :keyword:`return` statement, the :keyword:`!finally` clause will execute just prior to the :keyword:`!break`, :keyword:`!continue` or :keyword:`!return` statement's execution. * If a :keyword:`!finally` clause includes a :keyword:`!return`...
python, official-docs, cpython, P0
Local_Trusted_Corpus
ecb12fe7-1ce3-4452-9cae-3ff99228ddc5
CPython Docs
file://datasets/cpython/Doc/tutorial/errors.rst
unknown
3d4c648c-7ce3-4a72-a411-a7b59c82fde0
54,025
supabase-export-v2
6104941c19642ba1
* If no exception occurs, the *except clause* is skipped and execution of the :keyword:`try` statement is finished. * If an exception occurs during execution of the :keyword:`try` clause, the rest of the clause is skipped. Then, if its type matches the exception named after the :keyword:`except` keyword, the *except ...
trusted_official_docs
CPython Docs
* If no exception occurs, the *except clause* is skipped and execution of the :keyword:`try` statement is finished. * If an exception occurs during execution of the :keyword:`try` clause, the rest of the clause is skipped. Then, if its type matches the exception named after the :keyword:`except` keyword, the *except ...
* If no exception occurs, the *except clause* is skipped and execution of the :keyword:`try` statement is finished. * If an exception occurs during execution of the :keyword:`try` clause, the rest of the clause is skipped. Then, if its type matches the exception named after the :keyword:`except` keyword, the *except ...
python, official-docs, cpython, P0
Local_Trusted_Corpus
eebad16f-9470-42bd-a5a5-dc666744a160
CPython Docs
file://datasets/cpython/Doc/tutorial/errors.rst
unknown
3d4c648c-7ce3-4a72-a411-a7b59c82fde0
54,024
supabase-export-v2
f37d87d5f6e7b7f7
* First, the *try clause* (the statement(s) between the :keyword:`try` and :keyword:`except` keywords) is executed. * If no exception occurs, the *except clause* is skipped and execution of the :keyword:`try` statement is finished.
trusted_official_docs
CPython Docs
* First, the *try clause* (the statement(s) between the :keyword:`try` and :keyword:`except` keywords) is executed. * If no exception occurs, the *except clause* is skipped and execution of the :keyword:`try` statement is finished.
* First, the *try clause* (the statement(s) between the :keyword:`try` and :keyword:`except` keywords) is executed. * If no exception occurs, the *except clause* is skipped and execution of the :keyword:`try` statement is finished.
python, official-docs, cpython, P0
Local_Trusted_Corpus
f1873bf9-e0ca-4697-bc11-8db9103fe82a
CPython Docs
file://datasets/cpython/Doc/tutorial/errors.rst
unknown
3d4c648c-7ce3-4a72-a411-a7b59c82fde0
54,028
supabase-export-v2
db26ab320476b4dd
that occur in the corresponding *try clause*, not in other handlers of the same :keyword:`!try` statement. An *except clause* may name multiple exceptions, for example:: ... except RuntimeError, TypeError, NameError: ... pass
trusted_official_docs
CPython Docs
that occur in the corresponding *try clause*, not in other handlers of the same :keyword:`!try` statement. An *except clause* may name multiple exceptions, for example:: ... except RuntimeError, TypeError, NameError: ... pass
that occur in the corresponding *try clause*, not in other handlers of the same :keyword:`!try` statement. An *except clause* may name multiple exceptions, for example:: ... except RuntimeError, TypeError, NameError: ... pass
python, official-docs, cpython, P0
Local_Trusted_Corpus
f4632ffa-cd34-442a-bbf3-f0ad9ac3ecf0
CPython Docs
file://datasets/cpython/Doc/tutorial/errors.rst
unknown
3d4c648c-7ce3-4a72-a411-a7b59c82fde0
54,062
supabase-export-v2
deec4a2aa8209bc7
This can be useful when you are transforming exceptions. For example:: >>> def func(): ... raise ConnectionError ... >>> try: ... func() ... except ConnectionError as exc: ... raise RuntimeError('Failed to open database') from exc ... Traceback (most recent call last): File "<stdin>", line 2, in <module> func()...
trusted_official_docs
CPython Docs
This can be useful when you are transforming exceptions. For example:: >>> def func(): ... raise ConnectionError ... >>> try: ... func() ... except ConnectionError as exc: ... raise RuntimeError('Failed to open database') from exc ... Traceback (most recent call last): File "<stdin>", line 2, in <module> func()...
This can be useful when you are transforming exceptions. For example:: >>> def func(): ... raise ConnectionError ... >>> try: ... func() ... except ConnectionError as exc: ... raise RuntimeError('Failed to open database') from exc ... Traceback (most recent call last): File "<stdin>", line 2, in <module> func()...
python, official-docs, cpython, P0
Local_Trusted_Corpus
fe78d947-8b67-4108-b68e-eb49f152268e
CPython Docs
file://datasets/cpython/Doc/tutorial/errors.rst
unknown
3d4c648c-7ce3-4a72-a411-a7b59c82fde0
54,008
supabase-export-v2
7390b16b36fb4c8c
Syntax errors, also known as parsing errors, are perhaps the most common kind of complaint you get while you are still learning Python:: >>> while True print('Hello world') File "<stdin>", line 1 while True print('Hello world') ^^^^^ SyntaxError: invalid syntax
trusted_official_docs
CPython Docs
Syntax errors, also known as parsing errors, are perhaps the most common kind of complaint you get while you are still learning Python:: >>> while True print('Hello world') File "<stdin>", line 1 while True print('Hello world') ^^^^^ SyntaxError: invalid syntax
Syntax errors, also known as parsing errors, are perhaps the most common kind of complaint you get while you are still learning Python:: >>> while True print('Hello world') File "<stdin>", line 1 while True print('Hello world') ^^^^^ SyntaxError: invalid syntax
python, official-docs, cpython, P0
Local_Trusted_Corpus
019d9d9e-dfa3-4a1f-b1d1-bcb67ff4cf5c
CPython Docs
file://datasets/cpython/Doc/tutorial/inputoutput.rst
unknown
7b3a4c1f-2443-4c0c-bdfd-60ba87d122ae
54,184
supabase-export-v2
04b1af4f04270bea
file in :dfn:`binary mode`. Binary mode data is read and written as :class:`bytes` objects. You can not specify *encoding* when opening file in binary mode. In text mode, the default when reading is to convert platform-specific line endings (``\n`` on Unix, ``\r\n`` on Windows) to just ``\n``. When writing in text mode...
trusted_official_docs
CPython Docs
file in :dfn:`binary mode`. Binary mode data is read and written as :class:`bytes` objects. You can not specify *encoding* when opening file in binary mode. In text mode, the default when reading is to convert platform-specific line endings (``\n`` on Unix, ``\r\n`` on Windows) to just ``\n``. When writing in text mode...
file in :dfn:`binary mode`. Binary mode data is read and written as :class:`bytes` objects. You can not specify *encoding* when opening file in binary mode. In text mode, the default when reading is to convert platform-specific line endings (``\n`` on Unix, ``\r\n`` on Windows) to just ``\n``. When writing in text mode...
python, official-docs, cpython, P0
Local_Trusted_Corpus
0b931008-cd00-4e77-bb85-e6ab7131066f
CPython Docs
file://datasets/cpython/Doc/tutorial/inputoutput.rst
unknown
7b3a4c1f-2443-4c0c-bdfd-60ba87d122ae
54,216
supabase-export-v2
c522a3e81a57b6f5
its numeric value 123. When you want to save more complex data types like nested lists and dictionaries, parsing and serializing by hand becomes complicated. Rather than having users constantly writing and debugging code to save complicated data types to files, Python allows you to use the popular data interchange form...
trusted_official_docs
CPython Docs
its numeric value 123. When you want to save more complex data types like nested lists and dictionaries, parsing and serializing by hand becomes complicated. Rather than having users constantly writing and debugging code to save complicated data types to files, Python allows you to use the popular data interchange form...
its numeric value 123. When you want to save more complex data types like nested lists and dictionaries, parsing and serializing by hand becomes complicated. Rather than having users constantly writing and debugging code to save complicated data types to files, Python allows you to use the popular data interchange form...
python, official-docs, cpython, P0
Local_Trusted_Corpus
1411b803-906e-48de-bb44-7423e7d41a9e
CPython Docs
file://datasets/cpython/Doc/tutorial/inputoutput.rst
unknown
7b3a4c1f-2443-4c0c-bdfd-60ba87d122ae
54,155
supabase-export-v2
7150b3837f7df764
by name instead of by position. This can be done by simply passing the dict and using square brackets ``'[]'`` to access the keys. :: >>> table = {'Sjoerd': 4127, 'Jack': 4098, 'Dcab': 8637678} >>> print('Jack: {0[Jack]:d}; Sjoerd: {0[Sjoerd]:d}; ' ... 'Dcab: {0[Dcab]:d}'.format(table)) Jack: 4098; Sjoerd: 4127; Dca...
trusted_official_docs
CPython Docs
by name instead of by position. This can be done by simply passing the dict and using square brackets ``'[]'`` to access the keys. :: >>> table = {'Sjoerd': 4127, 'Jack': 4098, 'Dcab': 8637678} >>> print('Jack: {0[Jack]:d}; Sjoerd: {0[Sjoerd]:d}; ' ... 'Dcab: {0[Dcab]:d}'.format(table)) Jack: 4098; Sjoerd: 4127; Dca...
by name instead of by position. This can be done by simply passing the dict and using square brackets ``'[]'`` to access the keys. :: >>> table = {'Sjoerd': 4127, 'Jack': 4098, 'Dcab': 8637678} >>> print('Jack: {0[Jack]:d}; Sjoerd: {0[Sjoerd]:d}; ' ... 'Dcab: {0[Dcab]:d}'.format(table)) Jack: 4098; Sjoerd: 4127; Dca...
python, official-docs, cpython, P0
Local_Trusted_Corpus
1624efec-9777-4162-8214-738fd59fec37
CPython Docs
file://datasets/cpython/Doc/tutorial/inputoutput.rst
unknown
7b3a4c1f-2443-4c0c-bdfd-60ba87d122ae
54,202
supabase-export-v2
e8afdb9fcce977c1
>>> for line in f: ... print(line, end='') ... This is the first line of the file. Second line of the file If you want to read all the lines of a file in a list you can also use ``list(f)`` or ``f.readlines()``.
trusted_official_docs
CPython Docs
>>> for line in f: ... print(line, end='') ... This is the first line of the file. Second line of the file If you want to read all the lines of a file in a list you can also use ``list(f)`` or ``f.readlines()``.
>>> for line in f: ... print(line, end='') ... This is the first line of the file. Second line of the file If you want to read all the lines of a file in a list you can also use ``list(f)`` or ``f.readlines()``.
python, official-docs, cpython, P0
Local_Trusted_Corpus
16598d88-7de5-45e7-a0d9-b37f121dc162
CPython Docs
file://datasets/cpython/Doc/tutorial/inputoutput.rst
unknown
7b3a4c1f-2443-4c0c-bdfd-60ba87d122ae
54,151
supabase-export-v2
dd7fc4f262319f57
If keyword arguments are used in the :meth:`str.format` method, their values are referred to by using the name of the argument. :: >>> print('This {food} is {adjective}.'.format( ... food='spam', adjective='absolutely horrible')) This spam is absolutely horrible.
trusted_official_docs
CPython Docs
If keyword arguments are used in the :meth:`str.format` method, their values are referred to by using the name of the argument. :: >>> print('This {food} is {adjective}.'.format( ... food='spam', adjective='absolutely horrible')) This spam is absolutely horrible.
If keyword arguments are used in the :meth:`str.format` method, their values are referred to by using the name of the argument. :: >>> print('This {food} is {adjective}.'.format( ... food='spam', adjective='absolutely horrible')) This spam is absolutely horrible.
python, official-docs, cpython, P0
Local_Trusted_Corpus
1c4b1a67-ae2f-4ae5-a3eb-f1267d16a49e
CPython Docs
file://datasets/cpython/Doc/tutorial/inputoutput.rst
unknown
7b3a4c1f-2443-4c0c-bdfd-60ba87d122ae
54,125
supabase-export-v2
35a3cb3c7f02f892
for negative numbers. The example also prints ``percentage`` multiplied by 100, with 2 decimal places and followed by a percent sign (see :ref:`formatspec` for details). * Finally, you can do all the string handling yourself by using string slicing and concatenation operations to create any layout you can imagine. The...
trusted_official_docs
CPython Docs
for negative numbers. The example also prints ``percentage`` multiplied by 100, with 2 decimal places and followed by a percent sign (see :ref:`formatspec` for details). * Finally, you can do all the string handling yourself by using string slicing and concatenation operations to create any layout you can imagine. The...
for negative numbers. The example also prints ``percentage`` multiplied by 100, with 2 decimal places and followed by a percent sign (see :ref:`formatspec` for details). * Finally, you can do all the string handling yourself by using string slicing and concatenation operations to create any layout you can imagine. The...
python, official-docs, cpython, P0
Local_Trusted_Corpus
20459072-9fa0-465b-b982-7b17c15eab10
CPython Docs
file://datasets/cpython/Doc/tutorial/inputoutput.rst
unknown
7b3a4c1f-2443-4c0c-bdfd-60ba87d122ae
54,126
supabase-export-v2
7cbda90ec0b83b7a
to create any layout you can imagine. The string type has some methods that perform useful operations for padding strings to a given column width. When you don't need fancy output but just want a quick display of some variables for debugging purposes, you can convert any value to a string with the :func:`repr` or :func...
trusted_official_docs
CPython Docs
to create any layout you can imagine. The string type has some methods that perform useful operations for padding strings to a given column width. When you don't need fancy output but just want a quick display of some variables for debugging purposes, you can convert any value to a string with the :func:`repr` or :func...
to create any layout you can imagine. The string type has some methods that perform useful operations for padding strings to a given column width. When you don't need fancy output but just want a quick display of some variables for debugging purposes, you can convert any value to a string with the :func:`repr` or :func...
python, official-docs, cpython, P0
Local_Trusted_Corpus
22b00370-d05a-4660-9d74-c5a37ac30315
CPython Docs
file://datasets/cpython/Doc/tutorial/inputoutput.rst
unknown
7b3a4c1f-2443-4c0c-bdfd-60ba87d122ae
54,150
supabase-export-v2
32d4e94ecad2f8ab
>>> print('{0} and {1}'.format('spam', 'eggs')) spam and eggs >>> print('{1} and {0}'.format('spam', 'eggs')) eggs and spam If keyword arguments are used in the :meth:`str.format` method, their values are referred to by using the name of the argument. ::
trusted_official_docs
CPython Docs
>>> print('{0} and {1}'.format('spam', 'eggs')) spam and eggs >>> print('{1} and {0}'.format('spam', 'eggs')) eggs and spam If keyword arguments are used in the :meth:`str.format` method, their values are referred to by using the name of the argument. ::
>>> print('{0} and {1}'.format('spam', 'eggs')) spam and eggs >>> print('{1} and {0}'.format('spam', 'eggs')) eggs and spam If keyword arguments are used in the :meth:`str.format` method, their values are referred to by using the name of the argument. ::
python, official-docs, cpython, P0
Local_Trusted_Corpus
24789043-0b8b-41da-a278-d891ec7fb40a
CPython Docs
file://datasets/cpython/Doc/tutorial/inputoutput.rst
unknown
7b3a4c1f-2443-4c0c-bdfd-60ba87d122ae
54,137
supabase-export-v2
f4b8aaec2441317b
>>> import math >>> print(f'The value of pi is approximately {math.pi:.3f}.') The value of pi is approximately 3.142. Passing an integer after the ``':'`` will cause that field to be a minimum number of characters wide. This is useful for making columns line up. ::
trusted_official_docs
CPython Docs
>>> import math >>> print(f'The value of pi is approximately {math.pi:.3f}.') The value of pi is approximately 3.142. Passing an integer after the ``':'`` will cause that field to be a minimum number of characters wide. This is useful for making columns line up. ::
>>> import math >>> print(f'The value of pi is approximately {math.pi:.3f}.') The value of pi is approximately 3.142. Passing an integer after the ``':'`` will cause that field to be a minimum number of characters wide. This is useful for making columns line up. ::
python, official-docs, cpython, P0
Local_Trusted_Corpus
24c71298-e418-4dd6-8466-aa8e7b1a7f1c
CPython Docs
file://datasets/cpython/Doc/tutorial/inputoutput.rst
unknown
7b3a4c1f-2443-4c0c-bdfd-60ba87d122ae
54,140
supabase-export-v2
025284e125aec45a
Other modifiers can be used to convert the value before it is formatted. ``'!a'`` applies :func:`ascii`, ``'!s'`` applies :func:`str`, and ``'!r'`` applies :func:`repr`:: >>> animals = 'eels' >>> print(f'My hovercraft is full of {animals}.') My hovercraft is full of eels. >>> print(f'My hovercraft is full of {animals...
trusted_official_docs
CPython Docs
Other modifiers can be used to convert the value before it is formatted. ``'!a'`` applies :func:`ascii`, ``'!s'`` applies :func:`str`, and ``'!r'`` applies :func:`repr`:: >>> animals = 'eels' >>> print(f'My hovercraft is full of {animals}.') My hovercraft is full of eels. >>> print(f'My hovercraft is full of {animals...
Other modifiers can be used to convert the value before it is formatted. ``'!a'`` applies :func:`ascii`, ``'!s'`` applies :func:`str`, and ``'!r'`` applies :func:`repr`:: >>> animals = 'eels' >>> print(f'My hovercraft is full of {animals}.') My hovercraft is full of eels. >>> print(f'My hovercraft is full of {animals...
python, official-docs, cpython, P0
Local_Trusted_Corpus
26618ab9-6662-44f9-aa43-37057392eb9d
CPython Docs
file://datasets/cpython/Doc/tutorial/inputoutput.rst
unknown
7b3a4c1f-2443-4c0c-bdfd-60ba87d122ae
54,131
supabase-export-v2
9dcb3f9cff472996
placeholders like ``$x`` and replacing them with values from a dictionary. This syntax is easy to use, although it offers much less control for formatting. .. index:: single: formatted string literal single: interpolated string literal single: string; formatted literal single: string; interpolated literal single: ...
trusted_official_docs
CPython Docs
placeholders like ``$x`` and replacing them with values from a dictionary. This syntax is easy to use, although it offers much less control for formatting. .. index:: single: formatted string literal single: interpolated string literal single: string; formatted literal single: string; interpolated literal single: ...
placeholders like ``$x`` and replacing them with values from a dictionary. This syntax is easy to use, although it offers much less control for formatting. .. index:: single: formatted string literal single: interpolated string literal single: string; formatted literal single: string; interpolated literal single: ...
python, official-docs, cpython, P0
Local_Trusted_Corpus
27ddfb0d-962d-49f3-9f6d-840132bc9a31
CPython Docs
file://datasets/cpython/Doc/tutorial/inputoutput.rst
unknown
7b3a4c1f-2443-4c0c-bdfd-60ba87d122ae
54,215
supabase-export-v2
2136b3e09deb2eaf
.. index:: pair: module; json Strings can easily be written to and read from a file. Numbers take a bit more effort, since the :meth:`~io.TextIOBase.read` method only returns strings, which will have to be passed to a function like :func:`int`, which takes a string like ``'123'`` and returns its numeric value 123. When...
trusted_official_docs
CPython Docs
.. index:: pair: module; json Strings can easily be written to and read from a file. Numbers take a bit more effort, since the :meth:`~io.TextIOBase.read` method only returns strings, which will have to be passed to a function like :func:`int`, which takes a string like ``'123'`` and returns its numeric value 123. When...
.. index:: pair: module; json Strings can easily be written to and read from a file. Numbers take a bit more effort, since the :meth:`~io.TextIOBase.read` method only returns strings, which will have to be passed to a function like :func:`int`, which takes a string like ``'123'`` and returns its numeric value 123. When...
python, official-docs, cpython, P0
Local_Trusted_Corpus
283519ea-3221-4486-b518-bee4a869dc2a
CPython Docs
file://datasets/cpython/Doc/tutorial/inputoutput.rst
unknown
7b3a4c1f-2443-4c0c-bdfd-60ba87d122ae
54,129
supabase-export-v2
1d73b3b7e42dd4b7
Some examples:: >>> s = 'Hello, world.' >>> str(s) 'Hello, world.' >>> repr(s) "'Hello, world.'" >>> str(1/7) '0.14285714285714285' >>> x = 10 * 3.25 >>> y = 200 * 200 >>> s = 'The value of x is ' + repr(x) + ', and y is ' + repr(y) + '...' >>> print(s) The value of x is 32.5, and y is 40000... >>> # The rep...
trusted_official_docs
CPython Docs
Some examples:: >>> s = 'Hello, world.' >>> str(s) 'Hello, world.' >>> repr(s) "'Hello, world.'" >>> str(1/7) '0.14285714285714285' >>> x = 10 * 3.25 >>> y = 200 * 200 >>> s = 'The value of x is ' + repr(x) + ', and y is ' + repr(y) + '...' >>> print(s) The value of x is 32.5, and y is 40000... >>> # The rep...
Some examples:: >>> s = 'Hello, world.' >>> str(s) 'Hello, world.' >>> repr(s) "'Hello, world.'" >>> str(1/7) '0.14285714285714285' >>> x = 10 * 3.25 >>> y = 200 * 200 >>> s = 'The value of x is ' + repr(x) + ', and y is ' + repr(y) + '...' >>> print(s) The value of x is 32.5, and y is 40000... >>> # The rep...
python, official-docs, cpython, P0
Local_Trusted_Corpus
3160be26-f971-498f-8f64-912f5b829b37
CPython Docs
file://datasets/cpython/Doc/tutorial/inputoutput.rst
unknown
7b3a4c1f-2443-4c0c-bdfd-60ba87d122ae
54,141
supabase-export-v2
d4ed08cf5b951863
print(f'My hovercraft is full of {animals}.') My hovercraft is full of eels. >>> print(f'My hovercraft is full of {animals!r}.') My hovercraft is full of 'eels'. The ``=`` specifier can be used to expand an expression to the text of the expression, an equal sign, then the representation of the evaluated expression:
trusted_official_docs
CPython Docs
print(f'My hovercraft is full of {animals}.') My hovercraft is full of eels. >>> print(f'My hovercraft is full of {animals!r}.') My hovercraft is full of 'eels'. The ``=`` specifier can be used to expand an expression to the text of the expression, an equal sign, then the representation of the evaluated expression:
print(f'My hovercraft is full of {animals}.') My hovercraft is full of eels. >>> print(f'My hovercraft is full of {animals!r}.') My hovercraft is full of 'eels'. The ``=`` specifier can be used to expand an expression to the text of the expression, an equal sign, then the representation of the evaluated expression:
python, official-docs, cpython, P0
Local_Trusted_Corpus
31921ec3-3715-4af9-920d-db42c07a10db
CPython Docs
file://datasets/cpython/Doc/tutorial/inputoutput.rst
unknown
7b3a4c1f-2443-4c0c-bdfd-60ba87d122ae
54,172
supabase-export-v2
5bd926d437a047ce
string), ``%`` conversion specifications in *format* are replaced with zero or more elements of *values*. This operation is commonly known as string interpolation. For example:: >>> import math >>> print('The value of pi is approximately %5.3f.' % math.pi) The value of pi is approximately 3.142.
trusted_official_docs
CPython Docs
string), ``%`` conversion specifications in *format* are replaced with zero or more elements of *values*. This operation is commonly known as string interpolation. For example:: >>> import math >>> print('The value of pi is approximately %5.3f.' % math.pi) The value of pi is approximately 3.142.
string), ``%`` conversion specifications in *format* are replaced with zero or more elements of *values*. This operation is commonly known as string interpolation. For example:: >>> import math >>> print('The value of pi is approximately %5.3f.' % math.pi) The value of pi is approximately 3.142.
python, official-docs, cpython, P0
Local_Trusted_Corpus
338064df-277f-4ac0-8954-1bf62f9e33e8
CPython Docs
file://datasets/cpython/Doc/tutorial/inputoutput.rst
unknown
7b3a4c1f-2443-4c0c-bdfd-60ba87d122ae
54,136
supabase-export-v2
269a4565b6330f14
can follow the expression. This allows greater control over how the value is formatted. The following example rounds pi to three places after the decimal:: >>> import math >>> print(f'The value of pi is approximately {math.pi:.3f}.') The value of pi is approximately 3.142.
trusted_official_docs
CPython Docs
can follow the expression. This allows greater control over how the value is formatted. The following example rounds pi to three places after the decimal:: >>> import math >>> print(f'The value of pi is approximately {math.pi:.3f}.') The value of pi is approximately 3.142.
can follow the expression. This allows greater control over how the value is formatted. The following example rounds pi to three places after the decimal:: >>> import math >>> print(f'The value of pi is approximately {math.pi:.3f}.') The value of pi is approximately 3.142.
python, official-docs, cpython, P0
Local_Trusted_Corpus
3776f1f2-82cc-40cf-8b82-c184729e67e8
CPython Docs
file://datasets/cpython/Doc/tutorial/inputoutput.rst
unknown
7b3a4c1f-2443-4c0c-bdfd-60ba87d122ae
54,211
supabase-export-v2
0cd5ee41e9259903
end with ``seek(0, 2)``) and the only valid *offset* values are those returned from the ``f.tell()``, or zero. Any other *offset* value produces undefined behaviour. File objects have some additional methods, such as :meth:`~io.IOBase.isatty` and :meth:`~io.IOBase.truncate` which are less frequently used; consult the L...
trusted_official_docs
CPython Docs
end with ``seek(0, 2)``) and the only valid *offset* values are those returned from the ``f.tell()``, or zero. Any other *offset* value produces undefined behaviour. File objects have some additional methods, such as :meth:`~io.IOBase.isatty` and :meth:`~io.IOBase.truncate` which are less frequently used; consult the L...
end with ``seek(0, 2)``) and the only valid *offset* values are those returned from the ``f.tell()``, or zero. Any other *offset* value produces undefined behaviour. File objects have some additional methods, such as :meth:`~io.IOBase.isatty` and :meth:`~io.IOBase.truncate` which are less frequently used; consult the L...
python, official-docs, cpython, P0
Local_Trusted_Corpus
3b7f5f38-d5df-4455-b746-097448db9314
CPython Docs
file://datasets/cpython/Doc/tutorial/inputoutput.rst
unknown
7b3a4c1f-2443-4c0c-bdfd-60ba87d122ae
54,207
supabase-export-v2
8a733779e544ed7f
>>> value = ('the answer', 42) >>> s = str(value) # convert the tuple to string >>> f.write(s) 18 ``f.tell()`` returns an integer giving the file object's current position in the file represented as number of bytes from the beginning of the file when in binary mode and an opaque number when in text mode.
trusted_official_docs
CPython Docs
>>> value = ('the answer', 42) >>> s = str(value) # convert the tuple to string >>> f.write(s) 18 ``f.tell()`` returns an integer giving the file object's current position in the file represented as number of bytes from the beginning of the file when in binary mode and an opaque number when in text mode.
>>> value = ('the answer', 42) >>> s = str(value) # convert the tuple to string >>> f.write(s) 18 ``f.tell()`` returns an integer giving the file object's current position in the file represented as number of bytes from the beginning of the file when in binary mode and an opaque number when in text mode.
python, official-docs, cpython, P0
Local_Trusted_Corpus
3c7a4fcc-19b2-46f1-9f84-9c244b00488f
CPython Docs
file://datasets/cpython/Doc/tutorial/inputoutput.rst
unknown
7b3a4c1f-2443-4c0c-bdfd-60ba87d122ae
54,116
supabase-export-v2
1757d0afe18efd63
Fancier Output Formatting ========================= So far we've encountered two ways of writing values: *expression statements* and the :func:`print` function. (A third way is using the :meth:`~io.TextIOBase.write` method of file objects; the standard output file can be referenced as ``sys.stdout``. See the Library Re...
trusted_official_docs
CPython Docs
Fancier Output Formatting ========================= So far we've encountered two ways of writing values: *expression statements* and the :func:`print` function. (A third way is using the :meth:`~io.TextIOBase.write` method of file objects; the standard output file can be referenced as ``sys.stdout``. See the Library Re...
Fancier Output Formatting ========================= So far we've encountered two ways of writing values: *expression statements* and the :func:`print` function. (A third way is using the :meth:`~io.TextIOBase.write` method of file objects; the standard output file can be referenced as ``sys.stdout``. See the Library Re...
python, official-docs, cpython, P0
Local_Trusted_Corpus
3f1db6e2-4ba2-457b-a362-98c060b59f5c
CPython Docs
file://datasets/cpython/Doc/tutorial/inputoutput.rst
unknown
7b3a4c1f-2443-4c0c-bdfd-60ba87d122ae
54,156
supabase-export-v2
acf6785faf602fe9
>>> table = {'Sjoerd': 4127, 'Jack': 4098, 'Dcab': 8637678} >>> print('Jack: {0[Jack]:d}; Sjoerd: {0[Sjoerd]:d}; ' ... 'Dcab: {0[Dcab]:d}'.format(table)) Jack: 4098; Sjoerd: 4127; Dcab: 8637678 This could also be done by passing the ``table`` dictionary as keyword arguments with the ``**`` notation. ::
trusted_official_docs
CPython Docs
>>> table = {'Sjoerd': 4127, 'Jack': 4098, 'Dcab': 8637678} >>> print('Jack: {0[Jack]:d}; Sjoerd: {0[Sjoerd]:d}; ' ... 'Dcab: {0[Dcab]:d}'.format(table)) Jack: 4098; Sjoerd: 4127; Dcab: 8637678 This could also be done by passing the ``table`` dictionary as keyword arguments with the ``**`` notation. ::
>>> table = {'Sjoerd': 4127, 'Jack': 4098, 'Dcab': 8637678} >>> print('Jack: {0[Jack]:d}; Sjoerd: {0[Sjoerd]:d}; ' ... 'Dcab: {0[Dcab]:d}'.format(table)) Jack: 4098; Sjoerd: 4127; Dcab: 8637678 This could also be done by passing the ``table`` dictionary as keyword arguments with the ``**`` notation. ::
python, official-docs, cpython, P0
Local_Trusted_Corpus
4068a6ca-d077-44cf-9cc2-0e9da8dc7593
CPython Docs
file://datasets/cpython/Doc/tutorial/inputoutput.rst
unknown
7b3a4c1f-2443-4c0c-bdfd-60ba87d122ae
54,149
supabase-export-v2
11762249e6c8d9ae
the :meth:`str.format` method. A number in the brackets can be used to refer to the position of the object passed into the :meth:`str.format` method. :: >>> print('{0} and {1}'.format('spam', 'eggs')) spam and eggs >>> print('{1} and {0}'.format('spam', 'eggs')) eggs and spam
trusted_official_docs
CPython Docs
the :meth:`str.format` method. A number in the brackets can be used to refer to the position of the object passed into the :meth:`str.format` method. :: >>> print('{0} and {1}'.format('spam', 'eggs')) spam and eggs >>> print('{1} and {0}'.format('spam', 'eggs')) eggs and spam
the :meth:`str.format` method. A number in the brackets can be used to refer to the position of the object passed into the :meth:`str.format` method. :: >>> print('{0} and {1}'.format('spam', 'eggs')) spam and eggs >>> print('{1} and {0}'.format('spam', 'eggs')) eggs and spam
python, official-docs, cpython, P0
Local_Trusted_Corpus
4bcee692-6025-4d31-8354-825f6818778a
CPython Docs
file://datasets/cpython/Doc/tutorial/inputoutput.rst
unknown
7b3a4c1f-2443-4c0c-bdfd-60ba87d122ae
54,143
supabase-export-v2
0971fdb9b53ccb8d
>>> bugs = 'roaches' >>> count = 13 >>> area = 'living room' >>> print(f'Debugging {bugs=} {count=} {area=}') Debugging bugs='roaches' count=13 area='living room' See :ref:`self-documenting expressions <bpo-36817-whatsnew>` for more information on the ``=`` specifier. For a reference on these format specifications, see...
trusted_official_docs
CPython Docs
>>> bugs = 'roaches' >>> count = 13 >>> area = 'living room' >>> print(f'Debugging {bugs=} {count=} {area=}') Debugging bugs='roaches' count=13 area='living room' See :ref:`self-documenting expressions <bpo-36817-whatsnew>` for more information on the ``=`` specifier. For a reference on these format specifications, see...
>>> bugs = 'roaches' >>> count = 13 >>> area = 'living room' >>> print(f'Debugging {bugs=} {count=} {area=}') Debugging bugs='roaches' count=13 area='living room' See :ref:`self-documenting expressions <bpo-36817-whatsnew>` for more information on the ``=`` specifier. For a reference on these format specifications, see...
python, official-docs, cpython, P0
Local_Trusted_Corpus
4c5b057c-6c43-4445-94e2-08de8fe7b1d3
CPython Docs
file://datasets/cpython/Doc/tutorial/inputoutput.rst
unknown
7b3a4c1f-2443-4c0c-bdfd-60ba87d122ae
54,201
supabase-export-v2
7f296605c3ce669c
For reading lines from a file, you can loop over the file object. This is memory efficient, fast, and leads to simple code:: >>> for line in f: ... print(line, end='') ... This is the first line of the file. Second line of the file
trusted_official_docs
CPython Docs
For reading lines from a file, you can loop over the file object. This is memory efficient, fast, and leads to simple code:: >>> for line in f: ... print(line, end='') ... This is the first line of the file. Second line of the file
For reading lines from a file, you can loop over the file object. This is memory efficient, fast, and leads to simple code:: >>> for line in f: ... print(line, end='') ... This is the first line of the file. Second line of the file
python, official-docs, cpython, P0
Local_Trusted_Corpus
4e2af438-f08e-46a6-a86a-cae76f609802
CPython Docs
file://datasets/cpython/Doc/tutorial/inputoutput.rst
unknown
7b3a4c1f-2443-4c0c-bdfd-60ba87d122ae
54,130
supabase-export-v2
b52577d9074af0f9
repr(hello) >>> print(hellos) 'hello, world\n' >>> # The argument to repr() may be any Python object: >>> repr((x, y, ('spam', 'eggs'))) "(32.5, 40000, ('spam', 'eggs'))" The :mod:`string` module contains support for a simple templating approach based upon regular expressions, via :class:`string.Template`. This offers ...
trusted_official_docs
CPython Docs
repr(hello) >>> print(hellos) 'hello, world\n' >>> # The argument to repr() may be any Python object: >>> repr((x, y, ('spam', 'eggs'))) "(32.5, 40000, ('spam', 'eggs'))" The :mod:`string` module contains support for a simple templating approach based upon regular expressions, via :class:`string.Template`. This offers ...
repr(hello) >>> print(hellos) 'hello, world\n' >>> # The argument to repr() may be any Python object: >>> repr((x, y, ('spam', 'eggs'))) "(32.5, 40000, ('spam', 'eggs'))" The :mod:`string` module contains support for a simple templating approach based upon regular expressions, via :class:`string.Template`. This offers ...
python, official-docs, cpython, P0
Local_Trusted_Corpus
4f876051-8133-489c-825b-38eb71e9cb9e
CPython Docs
file://datasets/cpython/Doc/tutorial/inputoutput.rst
unknown
7b3a4c1f-2443-4c0c-bdfd-60ba87d122ae
54,206
supabase-export-v2
5611aff285f70039
of objects need to be converted -- either to a string (in text mode) or a bytes object (in binary mode) -- before writing them:: >>> value = ('the answer', 42) >>> s = str(value) # convert the tuple to string >>> f.write(s) 18
trusted_official_docs
CPython Docs
of objects need to be converted -- either to a string (in text mode) or a bytes object (in binary mode) -- before writing them:: >>> value = ('the answer', 42) >>> s = str(value) # convert the tuple to string >>> f.write(s) 18
of objects need to be converted -- either to a string (in text mode) or a bytes object (in binary mode) -- before writing them:: >>> value = ('the answer', 42) >>> s = str(value) # convert the tuple to string >>> f.write(s) 18
python, official-docs, cpython, P0
Local_Trusted_Corpus
5a47a790-5a9f-4c93-9648-cbf2761b8e09
CPython Docs
file://datasets/cpython/Doc/tutorial/inputoutput.rst
unknown
7b3a4c1f-2443-4c0c-bdfd-60ba87d122ae
54,210
supabase-export-v2
980fc40cafe9ba9f
6th byte in the file 5 >>> f.read(1) b'5' >>> f.seek(-3, 2) # Go to the 3rd byte before the end 13 >>> f.read(1) b'd' In text files (those opened without a ``b`` in the mode string), only seeks relative to the beginning of the file are allowed (the exception being seeking to the very file end with ``seek(0, 2)``) and t...
trusted_official_docs
CPython Docs
6th byte in the file 5 >>> f.read(1) b'5' >>> f.seek(-3, 2) # Go to the 3rd byte before the end 13 >>> f.read(1) b'd' In text files (those opened without a ``b`` in the mode string), only seeks relative to the beginning of the file are allowed (the exception being seeking to the very file end with ``seek(0, 2)``) and t...
6th byte in the file 5 >>> f.read(1) b'5' >>> f.seek(-3, 2) # Go to the 3rd byte before the end 13 >>> f.read(1) b'd' In text files (those opened without a ``b`` in the mode string), only seeks relative to the beginning of the file are allowed (the exception being seeking to the very file end with ``seek(0, 2)``) and t...
python, official-docs, cpython, P0
Local_Trusted_Corpus
5b7ad8e5-28d1-4d81-84bd-0edea79993e1
CPython Docs
file://datasets/cpython/Doc/tutorial/inputoutput.rst
unknown
7b3a4c1f-2443-4c0c-bdfd-60ba87d122ae
54,142
supabase-export-v2
2991a14c2330e226
``=`` specifier can be used to expand an expression to the text of the expression, an equal sign, then the representation of the evaluated expression: >>> bugs = 'roaches' >>> count = 13 >>> area = 'living room' >>> print(f'Debugging {bugs=} {count=} {area=}') Debugging bugs='roaches' count=13 area='living room'
trusted_official_docs
CPython Docs
``=`` specifier can be used to expand an expression to the text of the expression, an equal sign, then the representation of the evaluated expression: >>> bugs = 'roaches' >>> count = 13 >>> area = 'living room' >>> print(f'Debugging {bugs=} {count=} {area=}') Debugging bugs='roaches' count=13 area='living room'
``=`` specifier can be used to expand an expression to the text of the expression, an equal sign, then the representation of the evaluated expression: >>> bugs = 'roaches' >>> count = 13 >>> area = 'living room' >>> print(f'Debugging {bugs=} {count=} {area=}') Debugging bugs='roaches' count=13 area='living room'
python, official-docs, cpython, P0
Local_Trusted_Corpus
5e0565f5-3743-4a3e-8219-0e698163d53c
CPython Docs
file://datasets/cpython/Doc/tutorial/inputoutput.rst
unknown
7b3a4c1f-2443-4c0c-bdfd-60ba87d122ae
54,162
supabase-export-v2
916fbb321ce290ae
8 3 9 27 4 16 64 5 25 125 6 36 216 7 49 343 8 64 512 9 81 729 10 100 1000 For a complete overview of string formatting with :meth:`str.format`, see :ref:`formatstrings`.
trusted_official_docs
CPython Docs
8 3 9 27 4 16 64 5 25 125 6 36 216 7 49 343 8 64 512 9 81 729 10 100 1000 For a complete overview of string formatting with :meth:`str.format`, see :ref:`formatstrings`.
8 3 9 27 4 16 64 5 25 125 6 36 216 7 49 343 8 64 512 9 81 729 10 100 1000 For a complete overview of string formatting with :meth:`str.format`, see :ref:`formatstrings`.
python, official-docs, cpython, P0
Local_Trusted_Corpus
5edebbac-0c23-413d-b444-705cd232c163
CPython Docs
file://datasets/cpython/Doc/tutorial/inputoutput.rst
unknown
7b3a4c1f-2443-4c0c-bdfd-60ba87d122ae
54,225
supabase-export-v2
8beb83bc07a7f1e6
.. note:: JSON files must be encoded in UTF-8. Use ``encoding="utf-8"`` when opening JSON file as a :term:`text file` for both of reading and writing. This simple serialization technique can handle lists and dictionaries, but serializing arbitrary class instances in JSON requires a bit of extra effort. The reference fo...
trusted_official_docs
CPython Docs
.. note:: JSON files must be encoded in UTF-8. Use ``encoding="utf-8"`` when opening JSON file as a :term:`text file` for both of reading and writing. This simple serialization technique can handle lists and dictionaries, but serializing arbitrary class instances in JSON requires a bit of extra effort. The reference fo...
.. note:: JSON files must be encoded in UTF-8. Use ``encoding="utf-8"`` when opening JSON file as a :term:`text file` for both of reading and writing. This simple serialization technique can handle lists and dictionaries, but serializing arbitrary class instances in JSON requires a bit of extra effort. The reference fo...
python, official-docs, cpython, P0
Local_Trusted_Corpus
65a72675-7783-4743-8915-536c92691c7c
CPython Docs
file://datasets/cpython/Doc/tutorial/inputoutput.rst
unknown
7b3a4c1f-2443-4c0c-bdfd-60ba87d122ae
54,227
supabase-export-v2
4ccbe258f6fe8d5e
:mod:`pickle` - the pickle module Contrary to :ref:`JSON <tut-json>`, *pickle* is a protocol which allows the serialization of arbitrarily complex Python objects. As such, it is specific to Python and cannot be used to communicate with applications written in other languages. It is also insecure by default: deseria...
trusted_official_docs
CPython Docs
:mod:`pickle` - the pickle module Contrary to :ref:`JSON <tut-json>`, *pickle* is a protocol which allows the serialization of arbitrarily complex Python objects. As such, it is specific to Python and cannot be used to communicate with applications written in other languages. It is also insecure by default: deseria...
:mod:`pickle` - the pickle module Contrary to :ref:`JSON <tut-json>`, *pickle* is a protocol which allows the serialization of arbitrarily complex Python objects. As such, it is specific to Python and cannot be used to communicate with applications written in other languages. It is also insecure by default: deseria...
python, official-docs, cpython, P0
Local_Trusted_Corpus
66e43e58-9fe6-4e24-b42e-0f7e3b67d2d8
CPython Docs
file://datasets/cpython/Doc/tutorial/inputoutput.rst
unknown
7b3a4c1f-2443-4c0c-bdfd-60ba87d122ae
54,165
supabase-export-v2
65d30dea1cb03c83
Here's the same table of squares and cubes, formatted manually:: >>> for x in range(1, 11): ... print(repr(x).rjust(2), repr(x*x).rjust(3), end=' ') ... # Note use of 'end' on previous line ... print(repr(x*x*x).rjust(4)) ... 1 1 1 2 4 8 3 9 27 4 16 64 5 25 125 6 36 216 7 49 343 8 64 512 9 81 729 10 100 10...
trusted_official_docs
CPython Docs
Here's the same table of squares and cubes, formatted manually:: >>> for x in range(1, 11): ... print(repr(x).rjust(2), repr(x*x).rjust(3), end=' ') ... # Note use of 'end' on previous line ... print(repr(x*x*x).rjust(4)) ... 1 1 1 2 4 8 3 9 27 4 16 64 5 25 125 6 36 216 7 49 343 8 64 512 9 81 729 10 100 10...
Here's the same table of squares and cubes, formatted manually:: >>> for x in range(1, 11): ... print(repr(x).rjust(2), repr(x*x).rjust(3), end=' ') ... # Note use of 'end' on previous line ... print(repr(x*x*x).rjust(4)) ... 1 1 1 2 4 8 3 9 27 4 16 64 5 25 125 6 36 216 7 49 343 8 64 512 9 81 729 10 100 10...
python, official-docs, cpython, P0
Local_Trusted_Corpus
6c3bc08f-197f-4472-b812-9caabcacd76d
CPython Docs
file://datasets/cpython/Doc/tutorial/inputoutput.rst
unknown
7b3a4c1f-2443-4c0c-bdfd-60ba87d122ae
54,192
supabase-export-v2
a7afca7840c4a41f
After a file object is closed, either by a :keyword:`with` statement or by calling ``f.close()``, attempts to use the file object will automatically fail. :: >>> f.close() >>> f.read() Traceback (most recent call last): File "<stdin>", line 1, in <module> ValueError: I/O operation on closed file.
trusted_official_docs
CPython Docs
After a file object is closed, either by a :keyword:`with` statement or by calling ``f.close()``, attempts to use the file object will automatically fail. :: >>> f.close() >>> f.read() Traceback (most recent call last): File "<stdin>", line 1, in <module> ValueError: I/O operation on closed file.
After a file object is closed, either by a :keyword:`with` statement or by calling ``f.close()``, attempts to use the file object will automatically fail. :: >>> f.close() >>> f.read() Traceback (most recent call last): File "<stdin>", line 1, in <module> ValueError: I/O operation on closed file.
python, official-docs, cpython, P0
Local_Trusted_Corpus
736a8950-effe-44c3-920d-85947adebb41
CPython Docs
file://datasets/cpython/Doc/tutorial/inputoutput.rst
unknown
7b3a4c1f-2443-4c0c-bdfd-60ba87d122ae
54,196
supabase-export-v2
5fa5b94e63e25f0e
The rest of the examples in this section will assume that a file object called ``f`` has already been created. To read a file's contents, call ``f.read(size)``, which reads some quantity of data and returns it as a string (in text mode) or bytes object (in binary mode). *size* is an optional numeric argument. When *siz...
trusted_official_docs
CPython Docs
The rest of the examples in this section will assume that a file object called ``f`` has already been created. To read a file's contents, call ``f.read(size)``, which reads some quantity of data and returns it as a string (in text mode) or bytes object (in binary mode). *size* is an optional numeric argument. When *siz...
The rest of the examples in this section will assume that a file object called ``f`` has already been created. To read a file's contents, call ``f.read(size)``, which reads some quantity of data and returns it as a string (in text mode) or bytes object (in binary mode). *size* is an optional numeric argument. When *siz...
python, official-docs, cpython, P0
Local_Trusted_Corpus
758684ef-46a2-48d6-920a-a289ac2875c8
CPython Docs
file://datasets/cpython/Doc/tutorial/inputoutput.rst
unknown
7b3a4c1f-2443-4c0c-bdfd-60ba87d122ae
54,148
supabase-export-v2
6b8e33ac26e0640a
>>> print('We are the {} who say "{}!"'.format('knights', 'Ni')) We are the knights who say "Ni!" The brackets and characters within them (called format fields) are replaced with the objects passed into the :meth:`str.format` method. A number in the brackets can be used to refer to the position of the object passed int...
trusted_official_docs
CPython Docs
>>> print('We are the {} who say "{}!"'.format('knights', 'Ni')) We are the knights who say "Ni!" The brackets and characters within them (called format fields) are replaced with the objects passed into the :meth:`str.format` method. A number in the brackets can be used to refer to the position of the object passed int...
>>> print('We are the {} who say "{}!"'.format('knights', 'Ni')) We are the knights who say "Ni!" The brackets and characters within them (called format fields) are replaced with the objects passed into the :meth:`str.format` method. A number in the brackets can be used to refer to the position of the object passed int...
python, official-docs, cpython, P0
Local_Trusted_Corpus
76ebd638-69c3-4baa-9925-64153f2fc972
CPython Docs
file://datasets/cpython/Doc/tutorial/inputoutput.rst
unknown
7b3a4c1f-2443-4c0c-bdfd-60ba87d122ae
54,209
supabase-export-v2
332eadf7948626cd
the file as the reference point. *whence* can be omitted and defaults to 0, using the beginning of the file as the reference point. :: >>> f = open('workfile', 'rb+') >>> f.write(b'0123456789abcdef') 16 >>> f.seek(5) # Go to the 6th byte in the file 5 >>> f.read(1) b'5' >>> f.seek(-3, 2) # Go to the 3rd byte bef...
trusted_official_docs
CPython Docs
the file as the reference point. *whence* can be omitted and defaults to 0, using the beginning of the file as the reference point. :: >>> f = open('workfile', 'rb+') >>> f.write(b'0123456789abcdef') 16 >>> f.seek(5) # Go to the 6th byte in the file 5 >>> f.read(1) b'5' >>> f.seek(-3, 2) # Go to the 3rd byte bef...
the file as the reference point. *whence* can be omitted and defaults to 0, using the beginning of the file as the reference point. :: >>> f = open('workfile', 'rb+') >>> f.write(b'0123456789abcdef') 16 >>> f.seek(5) # Go to the 6th byte in the file 5 >>> f.read(1) b'5' >>> f.seek(-3, 2) # Go to the 3rd byte bef...
python, official-docs, cpython, P0
Local_Trusted_Corpus
78833f6c-b18b-4b5f-9770-062f4b42f617
CPython Docs
file://datasets/cpython/Doc/tutorial/inputoutput.rst
unknown
7b3a4c1f-2443-4c0c-bdfd-60ba87d122ae
54,203
supabase-export-v2
8c79326587faedd7
If you want to read all the lines of a file in a list you can also use ``list(f)`` or ``f.readlines()``. ``f.write(string)`` writes the contents of *string* to the file, returning the number of characters written. ::
trusted_official_docs
CPython Docs
If you want to read all the lines of a file in a list you can also use ``list(f)`` or ``f.readlines()``. ``f.write(string)`` writes the contents of *string* to the file, returning the number of characters written. ::
If you want to read all the lines of a file in a list you can also use ``list(f)`` or ``f.readlines()``. ``f.write(string)`` writes the contents of *string* to the file, returning the number of characters written. ::
python, official-docs, cpython, P0
Local_Trusted_Corpus
7b757b11-b7bc-4c9b-9232-f74d4417a456
CPython Docs
file://datasets/cpython/Doc/tutorial/inputoutput.rst
unknown
7b3a4c1f-2443-4c0c-bdfd-60ba87d122ae
54,219
supabase-export-v2
7aba9cf05b1def72
If you have an object ``x``, you can view its JSON string representation with a simple line of code:: >>> import json >>> x = [1, 'simple', 'list'] >>> json.dumps(x) '[1, "simple", "list"]'
trusted_official_docs
CPython Docs
If you have an object ``x``, you can view its JSON string representation with a simple line of code:: >>> import json >>> x = [1, 'simple', 'list'] >>> json.dumps(x) '[1, "simple", "list"]'
If you have an object ``x``, you can view its JSON string representation with a simple line of code:: >>> import json >>> x = [1, 'simple', 'list'] >>> json.dumps(x) '[1, "simple", "list"]'
python, official-docs, cpython, P0
Local_Trusted_Corpus
7dffba01-f0df-4fc1-ad74-2d346b03ae0d
CPython Docs
file://datasets/cpython/Doc/tutorial/inputoutput.rst
unknown
7b3a4c1f-2443-4c0c-bdfd-60ba87d122ae
54,134
supabase-export-v2
1197d54990d73f8a
Formatted String Literals ------------------------- :ref:`Formatted string literals <f-strings>` (also called f-strings for short) let you include the value of Python expressions inside a string by prefixing the string with ``f`` or ``F`` and writing expressions as ``{expression}``.
trusted_official_docs
CPython Docs
Formatted String Literals ------------------------- :ref:`Formatted string literals <f-strings>` (also called f-strings for short) let you include the value of Python expressions inside a string by prefixing the string with ``f`` or ``F`` and writing expressions as ``{expression}``.
Formatted String Literals ------------------------- :ref:`Formatted string literals <f-strings>` (also called f-strings for short) let you include the value of Python expressions inside a string by prefixing the string with ``f`` or ``F`` and writing expressions as ``{expression}``.
python, official-docs, cpython, P0
Local_Trusted_Corpus
7e872f98-c630-40bb-9e86-5cf018261d5d
CPython Docs
file://datasets/cpython/Doc/tutorial/inputoutput.rst
unknown
7b3a4c1f-2443-4c0c-bdfd-60ba87d122ae
54,113
supabase-export-v2
27c46a98427b79f3
**************** Input and Output **************** There are several ways to present the output of a program; data can be printed in a human-readable form, or written to a file for future use. This chapter will discuss some of the possibilities.
trusted_official_docs
CPython Docs
**************** Input and Output **************** There are several ways to present the output of a program; data can be printed in a human-readable form, or written to a file for future use. This chapter will discuss some of the possibilities.
**************** Input and Output **************** There are several ways to present the output of a program; data can be printed in a human-readable form, or written to a file for future use. This chapter will discuss some of the possibilities.
python, official-docs, cpython, P0
Local_Trusted_Corpus
80b00e4d-b05d-4539-ac7c-363fdc5c6465
CPython Docs
file://datasets/cpython/Doc/tutorial/inputoutput.rst
unknown
7b3a4c1f-2443-4c0c-bdfd-60ba87d122ae
54,157
supabase-export-v2
5bc38b335f9e5c43
This could also be done by passing the ``table`` dictionary as keyword arguments with the ``**`` notation. :: >>> table = {'Sjoerd': 4127, 'Jack': 4098, 'Dcab': 8637678} >>> print('Jack: {Jack:d}; Sjoerd: {Sjoerd:d}; Dcab: {Dcab:d}'.format(**table)) Jack: 4098; Sjoerd: 4127; Dcab: 8637678
trusted_official_docs
CPython Docs
This could also be done by passing the ``table`` dictionary as keyword arguments with the ``**`` notation. :: >>> table = {'Sjoerd': 4127, 'Jack': 4098, 'Dcab': 8637678} >>> print('Jack: {Jack:d}; Sjoerd: {Sjoerd:d}; Dcab: {Dcab:d}'.format(**table)) Jack: 4098; Sjoerd: 4127; Dcab: 8637678
This could also be done by passing the ``table`` dictionary as keyword arguments with the ``**`` notation. :: >>> table = {'Sjoerd': 4127, 'Jack': 4098, 'Dcab': 8637678} >>> print('Jack: {Jack:d}; Sjoerd: {Sjoerd:d}; Dcab: {Dcab:d}'.format(**table)) Jack: 4098; Sjoerd: 4127; Dcab: 8637678
python, official-docs, cpython, P0
Local_Trusted_Corpus
84423183-ba0d-4915-a529-999519d9ea1c
CPython Docs
file://datasets/cpython/Doc/tutorial/inputoutput.rst
unknown
7b3a4c1f-2443-4c0c-bdfd-60ba87d122ae
54,217
supabase-export-v2
a7357ba6777fb7aa
deserializing, the string representing the object may have been stored in a file or data, or sent over a network connection to some distant machine. .. note:: The JSON format is commonly used by modern applications to allow for data exchange. Many programmers are already familiar with it, which makes it a good choic...
trusted_official_docs
CPython Docs
deserializing, the string representing the object may have been stored in a file or data, or sent over a network connection to some distant machine. .. note:: The JSON format is commonly used by modern applications to allow for data exchange. Many programmers are already familiar with it, which makes it a good choic...
deserializing, the string representing the object may have been stored in a file or data, or sent over a network connection to some distant machine. .. note:: The JSON format is commonly used by modern applications to allow for data exchange. Many programmers are already familiar with it, which makes it a good choic...
python, official-docs, cpython, P0
Local_Trusted_Corpus
8ae65c9d-775f-4bf9-b19d-e9389b5f96c8
CPython Docs
file://datasets/cpython/Doc/tutorial/inputoutput.rst
unknown
7b3a4c1f-2443-4c0c-bdfd-60ba87d122ae
54,139
supabase-export-v2
dbe7afeb24ada153
4127, 'Jack': 4098, 'Dcab': 7678} >>> for name, phone in table.items(): ... print(f'{name:10} ==> {phone:10d}') ... Sjoerd ==> 4127 Jack ==> 4098 Dcab ==> 7678 Other modifiers can be used to convert the value before it is formatted. ``'!a'`` applies :func:`ascii`, ``'!s'`` applies :func:`str`, and ``'!r'`` applies :fun...
trusted_official_docs
CPython Docs
4127, 'Jack': 4098, 'Dcab': 7678} >>> for name, phone in table.items(): ... print(f'{name:10} ==> {phone:10d}') ... Sjoerd ==> 4127 Jack ==> 4098 Dcab ==> 7678 Other modifiers can be used to convert the value before it is formatted. ``'!a'`` applies :func:`ascii`, ``'!s'`` applies :func:`str`, and ``'!r'`` applies :fun...
4127, 'Jack': 4098, 'Dcab': 7678} >>> for name, phone in table.items(): ... print(f'{name:10} ==> {phone:10d}') ... Sjoerd ==> 4127 Jack ==> 4098 Dcab ==> 7678 Other modifiers can be used to convert the value before it is formatted. ``'!a'`` applies :func:`ascii`, ``'!s'`` applies :func:`str`, and ``'!r'`` applies :fun...
python, official-docs, cpython, P0
Local_Trusted_Corpus
8ec6ed50-96e8-4ea7-8f6b-382b63ed1037
CPython Docs
file://datasets/cpython/Doc/tutorial/inputoutput.rst
unknown
7b3a4c1f-2443-4c0c-bdfd-60ba87d122ae
54,185
supabase-export-v2
f0524f24a62797cb
but will corrupt binary data like that in :file:`JPEG` or :file:`EXE` files. Be very careful to use binary mode when reading and writing such files. It is good practice to use the :keyword:`with` keyword when dealing with file objects. The advantage is that the file is properly closed after its suite finishes, even if ...
trusted_official_docs
CPython Docs
but will corrupt binary data like that in :file:`JPEG` or :file:`EXE` files. Be very careful to use binary mode when reading and writing such files. It is good practice to use the :keyword:`with` keyword when dealing with file objects. The advantage is that the file is properly closed after its suite finishes, even if ...
but will corrupt binary data like that in :file:`JPEG` or :file:`EXE` files. Be very careful to use binary mode when reading and writing such files. It is good practice to use the :keyword:`with` keyword when dealing with file objects. The advantage is that the file is properly closed after its suite finishes, even if ...
python, official-docs, cpython, P0
Local_Trusted_Corpus
8fe4d4d9-bc6f-452f-a91e-8ded88bced75
CPython Docs
file://datasets/cpython/Doc/tutorial/inputoutput.rst
unknown
7b3a4c1f-2443-4c0c-bdfd-60ba87d122ae
54,118
supabase-export-v2
f8b316a0f5f0d0ae
Often you'll want more control over the formatting of your output than simply printing space-separated values. There are several ways to format output. * To use :ref:`formatted string literals <tut-f-strings>`, begin a string with ``f`` or ``F`` before the opening quotation mark or triple quotation mark. Inside this s...
trusted_official_docs
CPython Docs
Often you'll want more control over the formatting of your output than simply printing space-separated values. There are several ways to format output. * To use :ref:`formatted string literals <tut-f-strings>`, begin a string with ``f`` or ``F`` before the opening quotation mark or triple quotation mark. Inside this s...
Often you'll want more control over the formatting of your output than simply printing space-separated values. There are several ways to format output. * To use :ref:`formatted string literals <tut-f-strings>`, begin a string with ``f`` or ``F`` before the opening quotation mark or triple quotation mark. Inside this s...
python, official-docs, cpython, P0
Local_Trusted_Corpus
95c18a99-b4ce-42c8-a63d-c52ca36366e2
CPython Docs
file://datasets/cpython/Doc/tutorial/inputoutput.rst
unknown
7b3a4c1f-2443-4c0c-bdfd-60ba87d122ae
54,177
supabase-export-v2
607a8154ea3703ab
.. index:: pair: built-in function; open pair: object; file :func:`open` returns a :term:`file object`, and is most commonly used with two positional arguments and one keyword argument: ``open(filename, mode, encoding=None)``
trusted_official_docs
CPython Docs
.. index:: pair: built-in function; open pair: object; file :func:`open` returns a :term:`file object`, and is most commonly used with two positional arguments and one keyword argument: ``open(filename, mode, encoding=None)``
.. index:: pair: built-in function; open pair: object; file :func:`open` returns a :term:`file object`, and is most commonly used with two positional arguments and one keyword argument: ``open(filename, mode, encoding=None)``
python, official-docs, cpython, P0
Local_Trusted_Corpus
989d6a9c-2643-4287-b4ba-c56e77d3e649
CPython Docs
file://datasets/cpython/Doc/tutorial/inputoutput.rst
unknown
7b3a4c1f-2443-4c0c-bdfd-60ba87d122ae
54,161
supabase-export-v2
c844e7ddecc56069
As an example, the following lines produce a tidily aligned set of columns giving integers and their squares and cubes:: >>> for x in range(1, 11): ... print('{0:2d} {1:3d} {2:4d}'.format(x, x*x, x*x*x)) ... 1 1 1 2 4 8 3 9 27 4 16 64 5 25 125 6 36 216 7 49 343 8 64 512 9 81 729 10 100 1000
trusted_official_docs
CPython Docs
As an example, the following lines produce a tidily aligned set of columns giving integers and their squares and cubes:: >>> for x in range(1, 11): ... print('{0:2d} {1:3d} {2:4d}'.format(x, x*x, x*x*x)) ... 1 1 1 2 4 8 3 9 27 4 16 64 5 25 125 6 36 216 7 49 343 8 64 512 9 81 729 10 100 1000
As an example, the following lines produce a tidily aligned set of columns giving integers and their squares and cubes:: >>> for x in range(1, 11): ... print('{0:2d} {1:3d} {2:4d}'.format(x, x*x, x*x*x)) ... 1 1 1 2 4 8 3 9 27 4 16 64 5 25 125 6 36 216 7 49 343 8 64 512 9 81 729 10 100 1000
python, official-docs, cpython, P0
Local_Trusted_Corpus
9bfc2783-8132-41a3-944b-432bf1760295
CPython Docs
file://datasets/cpython/Doc/tutorial/inputoutput.rst
unknown
7b3a4c1f-2443-4c0c-bdfd-60ba87d122ae
54,189
supabase-export-v2
686b469a50d3105a
you're not using the :keyword:`with` keyword, then you should call ``f.close()`` to close the file and immediately free up any system resources used by it. .. warning:: Calling ``f.write()`` without using the :keyword:`!with` keyword or calling ``f.close()`` **might** result in the arguments of ``f.write()`` not bei...
trusted_official_docs
CPython Docs
you're not using the :keyword:`with` keyword, then you should call ``f.close()`` to close the file and immediately free up any system resources used by it. .. warning:: Calling ``f.write()`` without using the :keyword:`!with` keyword or calling ``f.close()`` **might** result in the arguments of ``f.write()`` not bei...
you're not using the :keyword:`with` keyword, then you should call ``f.close()`` to close the file and immediately free up any system resources used by it. .. warning:: Calling ``f.write()`` without using the :keyword:`!with` keyword or calling ``f.close()`` **might** result in the arguments of ``f.write()`` not bei...
python, official-docs, cpython, P0
Local_Trusted_Corpus
b540da11-c8ea-4f1c-847d-61d55bbceab6
CPython Docs
file://datasets/cpython/Doc/tutorial/inputoutput.rst
unknown
7b3a4c1f-2443-4c0c-bdfd-60ba87d122ae
54,160
supabase-export-v2
7c73a588d3e1bb32
>>> message = " ".join([f'{k}: ' + '{' + k +'};' for k in table.keys()]) >>> print(message.format(**table)) __name__: __main__; __doc__: None; __package__: None; __loader__: ... As an example, the following lines produce a tidily aligned set of columns giving integers and their squares and cubes::
trusted_official_docs
CPython Docs
>>> message = " ".join([f'{k}: ' + '{' + k +'};' for k in table.keys()]) >>> print(message.format(**table)) __name__: __main__; __doc__: None; __package__: None; __loader__: ... As an example, the following lines produce a tidily aligned set of columns giving integers and their squares and cubes::
>>> message = " ".join([f'{k}: ' + '{' + k +'};' for k in table.keys()]) >>> print(message.format(**table)) __name__: __main__; __doc__: None; __package__: None; __loader__: ... As an example, the following lines produce a tidily aligned set of columns giving integers and their squares and cubes::
python, official-docs, cpython, P0
Local_Trusted_Corpus