chunk_id large_stringlengths 36 36 | doc_type large_stringclasses 2
values | category large_stringclasses 17
values | document large_stringclasses 50
values | version_raw large_stringclasses 590
values | chunk_index int64 0 262 | text large_stringlengths 11 5.69k | file_path large_stringclasses 882
values |
|---|---|---|---|---|---|---|---|
7ee933b2-6408-5273-9b8a-af08a0faf1e7 | docs | python | python_stdlib2 | 310 | 3 | to customize their applications without having to alter the application.
The format uses placeholder names formed by `$` with valid Python identifiers
(alphanumeric characters and underscores). Surrounding the placeholder with
braces allows it to be followed by more alphanumeric letters with no intervening
spaces. Wri... | large_dataset/raw/docs/python/stdlib2/stdlib2_310.md |
1e88053f-4223-52de-bd39-9ac4ed56533f | docs | python | python_stdlib2 | 310 | 4 | [`safe_substitute()`](../library/string.html#string.Template.safe_substitute "string.Template.safe_substitute") method may be more appropriate —
it will leave placeholders unchanged if data is missing:
```None
>>> t = Template('Return the $item to $owner.')
>>> d = dict(item='unladen swallow')
>>> t.substitute(d)
Trac... | large_dataset/raw/docs/python/stdlib2/stdlib2_310.md |
7f1f4e80-92d0-5710-8f1b-60978b6089c5 | docs | python | python_stdlib2 | 310 | 5 | >>> for i, filename in enumerate(photofiles):
... base, ext = os.path.splitext(filename)
... newname = t.substitute(d=date, n=i, f=ext)
... print('{0} --> {1}'.format(filename, newname))
img_1074.jpg --> Ashley_0.jpg
img_1076.jpg --> Ashley_1.jpg
img_1077.jpg --> Ashley_2.jpg
```
Another application for t... | large_dataset/raw/docs/python/stdlib2/stdlib2_310.md |
0925f64c-f822-56f9-9fcb-0bbfd0c568d1 | docs | python | python_stdlib2 | 310 | 6 | how to loop through header information in a ZIP file without using the
[`zipfile`](../library/zipfile.html#module-zipfile "zipfile: Read and write ZIP-format archive files.") module. Pack codes `"H"` and `"I"` represent two and four
byte unsigned numbers respectively. The `"<"` indicates that they are
standard size and... | large_dataset/raw/docs/python/stdlib2/stdlib2_310.md |
465f0a6a-5986-53b0-83c5-1fa7b114a0a2 | docs | python | python_stdlib2 | 310 | 7 | ## 11.4. Multi-threading[¶](#multi-threading "Permalink to this headline")
Threading is a technique for decoupling tasks which are not sequentially
dependent. Threads can be used to improve the responsiveness of applications
that accept user input while other tasks run in the background. A related use
case is running ... | large_dataset/raw/docs/python/stdlib2/stdlib2_310.md |
6d9bfbbc-7223-50a0-b37c-750988ceaf87 | docs | python | python_stdlib2 | 310 | 8 | background = AsyncZip('mydata.txt', 'myarchive.zip')
background.start()
print('The main program continues to run in foreground.')
background.join() # Wait for the background task to finish
print('Main program waited until background was done.')
```
The principal challenge of multi-threaded applications is coordina... | large_dataset/raw/docs/python/stdlib2/stdlib2_310.md |
84cd2700-0099-5e61-af43-037dfb366eaa | docs | python | python_stdlib2 | 310 | 9 | coordination are easier to design, more readable, and more reliable.
## 11.5. Logging[¶](#logging "Permalink to this headline")
The [`logging`](../library/logging.html#module-logging "logging: Flexible event logging system for applications.") module offers a full featured and flexible logging system.
At its simplest,... | large_dataset/raw/docs/python/stdlib2/stdlib2_310.md |
c46944c6-9ef5-5c36-9665-13562c55b442 | docs | python | python_stdlib2 | 310 | 10 | through email, datagrams, sockets, or to an HTTP Server. New filters can select
different routing based on message priority: `DEBUG`,
`INFO`, `WARNING`, `ERROR`,
and `CRITICAL`.
The logging system can be configured directly from Python or can be loaded from
a user editable configuration file for customized logging wit... | large_dataset/raw/docs/python/stdlib2/stdlib2_310.md |
b9ec8e24-3c85-52b9-b449-aba492ebd6b8 | docs | python | python_stdlib2 | 310 | 11 | The [`weakref`](../library/weakref.html#module-weakref "weakref: Support for weak references and weak dictionaries.") module provides tools for tracking objects without creating a
reference. When the object is no longer needed, it is automatically removed
from a weakref table and a callback is triggered for weakref obj... | large_dataset/raw/docs/python/stdlib2/stdlib2_310.md |
12ed9d27-33d8-5904-b45b-03dafce343aa | docs | python | python_stdlib2 | 310 | 12 | Traceback (most recent call last):
File "<stdin>", line 1, in <module>
d['primary'] # entry was automatically removed
File "C:/python310/lib/weakref.py", line 46, in __getitem__
o = self.data[key]()
KeyError: 'primary'
```
## 11.7. Tools for Working with Lists[¶](#tools-for-working-with-list... | large_dataset/raw/docs/python/stdlib2/stdlib2_310.md |
f622da03-a178-5876-b34f-51e708e5071a | docs | python | python_stdlib2 | 310 | 13 | >>> from array import array
>>> a = array('H', [4000, 10, 700, 22222])
>>> sum(a)
26932
>>> a[1:3]
array('H', [10, 700])
```
The [`collections`](../library/collections.html#module-collections "collections: Container datatypes") module provides a [`deque()`](../library/collections.html#collections.deque "collections.de... | large_dataset/raw/docs/python/stdlib2/stdlib2_310.md |
777435fa-469f-5f69-aca0-100e9a6189ff | docs | python | python_stdlib2 | 310 | 14 | tools such as the [`bisect`](../library/bisect.html#module-bisect "bisect: Array bisection algorithms for binary searching.") module with functions for manipulating sorted
lists:
```None
>>> import bisect
>>> scores = [(100, 'perl'), (200, 'tcl'), (400, 'lua'), (500, 'python')]
>>> bisect.insort(scores, (300, 'ruby'))... | large_dataset/raw/docs/python/stdlib2/stdlib2_310.md |
b2d7d6bf-f9f5-5dc7-aff4-32bf746a6a1d | docs | python | python_stdlib2 | 310 | 15 | >>> [heappop(data) for i in range(3)] # fetch the three smallest entries
[-5, 0, 1]
```
## 11.8. Decimal Floating Point Arithmetic[¶](#decimal-floating-point-arithmetic "Permalink to this headline")
The [`decimal`](../library/decimal.html#module-decimal "decimal: Implementation of the General Decimal Arithmetic Spe... | large_dataset/raw/docs/python/stdlib2/stdlib2_310.md |
80caeaa7-66f3-56e6-9c5d-987d24299aa4 | docs | python | python_stdlib2 | 310 | 16 | results in decimal floating point and binary floating point. The difference
becomes significant if the results are rounded to the nearest cent:
```None
>>> from decimal import *
>>> round(Decimal('0.70') * Decimal('1.05'), 2)
Decimal('0.74')
>>> round(.70 * 1.05, 2)
0.73
```
The [`Decimal`](../library/decimal.html#de... | large_dataset/raw/docs/python/stdlib2/stdlib2_310.md |
df5c51a7-be09-5160-8630-9ec15280ec7b | docs | python | python_stdlib2 | 310 | 17 |
The [`decimal`](../library/decimal.html#module-decimal "decimal: Implementation of the General Decimal Arithmetic Specification.") module provides arithmetic with as much precision as needed:
```None
>>> getcontext().prec = 36
>>> Decimal(1) / Decimal(7)
Decimal('0.142857142857142857142857142857142857')
```
| large_dataset/raw/docs/python/stdlib2/stdlib2_310.md |
d2b84ab6-94cf-5f5d-a7b3-454ac7a2a682 | docs | python | python_stdlib2 | 311 | 0 | # 11.Brief Tour of the Standard Library — Part II¶
Source: https://docs.python.org/3.11/tutorial/stdlib2.html
Version: 3.11
This second tour covers more advanced modules that support professional
programming needs. These modules rarely occur in small scripts.
## 11.1. Output Formatting[¶](#output-formatting "Link to... | large_dataset/raw/docs/python/stdlib2/stdlib2_311.md |
f7517334-547b-5460-879a-5b3fd55cb661 | docs | python | python_stdlib2 | 311 | 1 | When the result is longer than one line, the “pretty printer” adds line breaks
and indentation to more clearly reveal data structure:
```None
>>> import pprint
>>> t = [[[['black', 'cyan'], 'white', ['green', 'red']], [['magenta',
... 'yellow'], 'blue']]]
...
>>> pprint.pprint(t, width=30)
[[[['black', 'cyan'],
... | large_dataset/raw/docs/python/stdlib2/stdlib2_311.md |
c71744b5-218a-572c-a92f-5f562cdd1d41 | docs | python | python_stdlib2 | 311 | 2 | The [`locale`](../library/locale.html#module-locale "locale: Internationalization services.") module accesses a database of culture specific data formats.
The grouping attribute of locale’s format function provides a direct way of
formatting numbers with group separators:
```None
>>> import locale
>>> locale.setlocale... | large_dataset/raw/docs/python/stdlib2/stdlib2_311.md |
cb090800-2aa7-5e1b-a06d-fb3a5071e2aa | docs | python | python_stdlib2 | 311 | 3 | to customize their applications without having to alter the application.
The format uses placeholder names formed by `$` with valid Python identifiers
(alphanumeric characters and underscores). Surrounding the placeholder with
braces allows it to be followed by more alphanumeric letters with no intervening
spaces. Wri... | large_dataset/raw/docs/python/stdlib2/stdlib2_311.md |
42cc583d-de1b-5782-9a97-0162df354dc3 | docs | python | python_stdlib2 | 311 | 4 | [`safe_substitute()`](../library/string.html#string.Template.safe_substitute "string.Template.safe_substitute") method may be more appropriate —
it will leave placeholders unchanged if data is missing:
```None
>>> t = Template('Return the $item to $owner.')
>>> d = dict(item='unladen swallow')
>>> t.substitute(d)
Trac... | large_dataset/raw/docs/python/stdlib2/stdlib2_311.md |
6ac0ccc7-2624-5402-a5ae-964a3299c80f | docs | python | python_stdlib2 | 311 | 5 | >>> for i, filename in enumerate(photofiles):
... base, ext = os.path.splitext(filename)
... newname = t.substitute(d=date, n=i, f=ext)
... print('{0} --> {1}'.format(filename, newname))
img_1074.jpg --> Ashley_0.jpg
img_1076.jpg --> Ashley_1.jpg
img_1077.jpg --> Ashley_2.jpg
```
Another application for t... | large_dataset/raw/docs/python/stdlib2/stdlib2_311.md |
9ca455c8-cbbd-57eb-a213-8964b6d8be3d | docs | python | python_stdlib2 | 311 | 6 | how to loop through header information in a ZIP file without using the
[`zipfile`](../library/zipfile.html#module-zipfile "zipfile: Read and write ZIP-format archive files.") module. Pack codes `"H"` and `"I"` represent two and four
byte unsigned numbers respectively. The `"<"` indicates that they are
standard size and... | large_dataset/raw/docs/python/stdlib2/stdlib2_311.md |
242e9882-b8ec-5c4e-869a-9c105f52f7ff | docs | python | python_stdlib2 | 311 | 7 | ## 11.4. Multi-threading[¶](#multi-threading "Link to this heading")
Threading is a technique for decoupling tasks which are not sequentially
dependent. Threads can be used to improve the responsiveness of applications
that accept user input while other tasks run in the background. A related use
case is running I/O in... | large_dataset/raw/docs/python/stdlib2/stdlib2_311.md |
78bb61b4-9a91-5813-84bc-8ccd361a37f0 | docs | python | python_stdlib2 | 311 | 8 | background = AsyncZip('mydata.txt', 'myarchive.zip')
background.start()
print('The main program continues to run in foreground.')
background.join() # Wait for the background task to finish
print('Main program waited until background was done.')
```
The principal challenge of multi-threaded applications is coordina... | large_dataset/raw/docs/python/stdlib2/stdlib2_311.md |
6d4e62df-406d-5d8d-b7e6-50878252ddd0 | docs | python | python_stdlib2 | 311 | 9 | coordination are easier to design, more readable, and more reliable.
## 11.5. Logging[¶](#logging "Link to this heading")
The [`logging`](../library/logging.html#module-logging "logging: Flexible event logging system for applications.") module offers a full featured and flexible logging system.
At its simplest, log m... | large_dataset/raw/docs/python/stdlib2/stdlib2_311.md |
d3a54ec9-68a6-58ad-ac9b-e49023df4e33 | docs | python | python_stdlib2 | 311 | 10 | through email, datagrams, sockets, or to an HTTP Server. New filters can select
different routing based on message priority: [`DEBUG`](../library/logging.html#logging.DEBUG "logging.DEBUG"),
[`INFO`](../library/logging.html#logging.INFO "logging.INFO"), [`WARNING`](../library/logging.html#logging.WARNING "logging.WARNI... | large_dataset/raw/docs/python/stdlib2/stdlib2_311.md |
f92e2068-9c8a-572d-87cf-e3f6027e9fa5 | docs | python | python_stdlib2 | 311 | 11 | This approach works fine for most applications but occasionally there is a need
to track objects only as long as they are being used by something else.
Unfortunately, just tracking them creates a reference that makes them permanent.
The [`weakref`](../library/weakref.html#module-weakref "weakref: Support for weak refer... | large_dataset/raw/docs/python/stdlib2/stdlib2_311.md |
1f79c57f-e6b7-57b4-a691-a84bb6849826 | docs | python | python_stdlib2 | 311 | 12 | >>> d['primary'] # fetch the object if it is still alive
10
>>> del a # remove the one reference
>>> gc.collect() # run garbage collection right away
0
>>> d['primary'] # entry was automatically removed
Traceback (most recent call last):
File "<stdin>... | large_dataset/raw/docs/python/stdlib2/stdlib2_311.md |
91e16094-6545-59d4-a8be-6175535b02c7 | docs | python | python_stdlib2 | 311 | 13 | a list that stores only homogeneous data and stores it more compactly. The
following example shows an array of numbers stored as two byte unsigned binary
numbers (typecode `"H"`) rather than the usual 16 bytes per entry for regular
lists of Python int objects:
```None
>>> from array import array
>>> a = array('H', [40... | large_dataset/raw/docs/python/stdlib2/stdlib2_311.md |
909a0381-9e82-5f99-bbfb-547047aa754f | docs | python | python_stdlib2 | 311 | 14 | def breadth_first_search(unsearched):
node = unsearched.popleft()
for m in gen_moves(node):
if is_goal(m):
return m
unsearched.append(m)
```
In addition to alternative list implementations, the library also offers other
tools such as the [`bisect`](../library/bisect.html#module-bise... | large_dataset/raw/docs/python/stdlib2/stdlib2_311.md |
b95093d7-9fb7-5063-8d76-bd5d9f5acf5e | docs | python | python_stdlib2 | 311 | 15 | ```None
>>> from heapq import heapify, heappop, heappush
>>> data = [1, 3, 5, 7, 9, 2, 4, 6, 8, 0]
>>> heapify(data) # rearrange the list into heap order
>>> heappush(data, -5) # add a new entry
>>> [heappop(data) for i in range(3)] # fetch the three smallest entries
[-5, 0, 1]
```... | large_dataset/raw/docs/python/stdlib2/stdlib2_311.md |
53d35542-b470-5c62-bdb9-6c3bd0bce237 | docs | python | python_stdlib2 | 311 | 16 | * control over rounding to meet legal or regulatory requirements,
* tracking of significant decimal places, or
* applications where the user expects the results to match calculations done by
hand.
For example, calculating a 5% tax on a 70 cent phone charge gives different
results in decimal floating point and binary... | large_dataset/raw/docs/python/stdlib2/stdlib2_311.md |
c640ae07-27b1-511c-990b-4677f6117246 | docs | python | python_stdlib2 | 311 | 17 | Exact representation enables the [`Decimal`](../library/decimal.html#decimal.Decimal "decimal.Decimal") class to perform
modulo calculations and equality tests that are unsuitable for binary floating
point:
```None
>>> Decimal('1.00') % Decimal('.10')
Decimal('0.00')
>>> 1.00 % 0.10
0.09999999999999995
>>> sum([Decim... | large_dataset/raw/docs/python/stdlib2/stdlib2_311.md |
dba33bc1-ef48-5734-859a-90a1be52694e | docs | python | python_stdlib2 | 312 | 0 | # 11.Brief Tour of the Standard Library — Part II¶
Source: https://docs.python.org/3.12/tutorial/stdlib2.html
Version: 3.12
This second tour covers more advanced modules that support professional
programming needs. These modules rarely occur in small scripts.
## 11.1. Output Formatting[¶](#output-formatting "Link to... | large_dataset/raw/docs/python/stdlib2/stdlib2_312.md |
6a3cf23c-5bee-5b72-a111-1cb37ed8e9bd | docs | python | python_stdlib2 | 312 | 1 | When the result is longer than one line, the “pretty printer” adds line breaks
and indentation to more clearly reveal data structure:
```None
>>> import pprint
>>> t = [[[['black', 'cyan'], 'white', ['green', 'red']], [['magenta',
... 'yellow'], 'blue']]]
...
>>> pprint.pprint(t, width=30)
[[[['black', 'cyan'],
... | large_dataset/raw/docs/python/stdlib2/stdlib2_312.md |
b0285fb5-6b45-5e2c-91c2-c03345a5d43c | docs | python | python_stdlib2 | 312 | 2 | The [`locale`](../library/locale.html#module-locale "locale: Internationalization services.") module accesses a database of culture specific data formats.
The grouping attribute of locale’s format function provides a direct way of
formatting numbers with group separators:
```None
>>> import locale
>>> locale.setlocale... | large_dataset/raw/docs/python/stdlib2/stdlib2_312.md |
3e252f96-2180-5708-aaed-96614def091c | docs | python | python_stdlib2 | 312 | 3 | to customize their applications without having to alter the application.
The format uses placeholder names formed by `$` with valid Python identifiers
(alphanumeric characters and underscores). Surrounding the placeholder with
braces allows it to be followed by more alphanumeric letters with no intervening
spaces. Wri... | large_dataset/raw/docs/python/stdlib2/stdlib2_312.md |
5b7f9aa1-dcfb-5aaf-b842-e5120b8d8a23 | docs | python | python_stdlib2 | 312 | 4 | [`safe_substitute()`](../library/string.html#string.Template.safe_substitute "string.Template.safe_substitute") method may be more appropriate —
it will leave placeholders unchanged if data is missing:
```None
>>> t = Template('Return the $item to $owner.')
>>> d = dict(item='unladen swallow')
>>> t.substitute(d)
Trac... | large_dataset/raw/docs/python/stdlib2/stdlib2_312.md |
eaba2bbb-1de6-537b-b098-b1750cb193d5 | docs | python | python_stdlib2 | 312 | 5 | >>> for i, filename in enumerate(photofiles):
... base, ext = os.path.splitext(filename)
... newname = t.substitute(d=date, n=i, f=ext)
... print('{0} --> {1}'.format(filename, newname))
img_1074.jpg --> Ashley_0.jpg
img_1076.jpg --> Ashley_1.jpg
img_1077.jpg --> Ashley_2.jpg
```
Another application for t... | large_dataset/raw/docs/python/stdlib2/stdlib2_312.md |
22a07751-b81c-579d-bdfb-8b7cf004f14d | docs | python | python_stdlib2 | 312 | 6 | how to loop through header information in a ZIP file without using the
[`zipfile`](../library/zipfile.html#module-zipfile "zipfile: Read and write ZIP-format archive files.") module. Pack codes `"H"` and `"I"` represent two and four
byte unsigned numbers respectively. The `"<"` indicates that they are
standard size and... | large_dataset/raw/docs/python/stdlib2/stdlib2_312.md |
eb9f307a-ae27-5e95-baad-5d4536f29b77 | docs | python | python_stdlib2 | 312 | 7 | ## 11.4. Multi-threading[¶](#multi-threading "Link to this heading")
Threading is a technique for decoupling tasks which are not sequentially
dependent. Threads can be used to improve the responsiveness of applications
that accept user input while other tasks run in the background. A related use
case is running I/O in... | large_dataset/raw/docs/python/stdlib2/stdlib2_312.md |
1333c74e-ad0b-5888-a0ef-a7ed022ddc92 | docs | python | python_stdlib2 | 312 | 8 | background = AsyncZip('mydata.txt', 'myarchive.zip')
background.start()
print('The main program continues to run in foreground.')
background.join() # Wait for the background task to finish
print('Main program waited until background was done.')
```
The principal challenge of multi-threaded applications is coordina... | large_dataset/raw/docs/python/stdlib2/stdlib2_312.md |
81de0705-9426-5e1c-98ef-c314da4fcc99 | docs | python | python_stdlib2 | 312 | 9 | coordination are easier to design, more readable, and more reliable.
## 11.5. Logging[¶](#logging "Link to this heading")
The [`logging`](../library/logging.html#module-logging "logging: Flexible event logging system for applications.") module offers a full featured and flexible logging system.
At its simplest, log m... | large_dataset/raw/docs/python/stdlib2/stdlib2_312.md |
4b5aac6c-d993-52d6-bf67-11286fa78583 | docs | python | python_stdlib2 | 312 | 10 | through email, datagrams, sockets, or to an HTTP Server. New filters can select
different routing based on message priority: [`DEBUG`](../library/logging.html#logging.DEBUG "logging.DEBUG"),
[`INFO`](../library/logging.html#logging.INFO "logging.INFO"), [`WARNING`](../library/logging.html#logging.WARNING "logging.WARNI... | large_dataset/raw/docs/python/stdlib2/stdlib2_312.md |
5b80ae7c-7263-5c17-8e4f-4c1b78cb5f93 | docs | python | python_stdlib2 | 312 | 11 | This approach works fine for most applications but occasionally there is a need
to track objects only as long as they are being used by something else.
Unfortunately, just tracking them creates a reference that makes them permanent.
The [`weakref`](../library/weakref.html#module-weakref "weakref: Support for weak refer... | large_dataset/raw/docs/python/stdlib2/stdlib2_312.md |
a3dc2093-78bb-523b-a220-69e82bbbd6ce | docs | python | python_stdlib2 | 312 | 12 | >>> d['primary'] # fetch the object if it is still alive
10
>>> del a # remove the one reference
>>> gc.collect() # run garbage collection right away
0
>>> d['primary'] # entry was automatically removed
Traceback (most recent call last):
File "<stdin>... | large_dataset/raw/docs/python/stdlib2/stdlib2_312.md |
72bb1900-f3f2-5caf-a963-08023475da6b | docs | python | python_stdlib2 | 312 | 13 | a list that stores only homogeneous data and stores it more compactly. The
following example shows an array of numbers stored as two byte unsigned binary
numbers (typecode `"H"`) rather than the usual 16 bytes per entry for regular
lists of Python int objects:
```None
>>> from array import array
>>> a = array('H', [40... | large_dataset/raw/docs/python/stdlib2/stdlib2_312.md |
2f2f748a-787b-504b-bf44-e0e9ea6673a5 | docs | python | python_stdlib2 | 312 | 14 | def breadth_first_search(unsearched):
node = unsearched.popleft()
for m in gen_moves(node):
if is_goal(m):
return m
unsearched.append(m)
```
In addition to alternative list implementations, the library also offers other
tools such as the [`bisect`](../library/bisect.html#module-bise... | large_dataset/raw/docs/python/stdlib2/stdlib2_312.md |
17f8c060-dcad-51f0-9118-531b58a6ea4b | docs | python | python_stdlib2 | 312 | 15 | ```None
>>> from heapq import heapify, heappop, heappush
>>> data = [1, 3, 5, 7, 9, 2, 4, 6, 8, 0]
>>> heapify(data) # rearrange the list into heap order
>>> heappush(data, -5) # add a new entry
>>> [heappop(data) for i in range(3)] # fetch the three smallest entries
[-5, 0, 1]
```... | large_dataset/raw/docs/python/stdlib2/stdlib2_312.md |
ae7a61bf-cebf-54f1-ba1e-287ad7adf746 | docs | python | python_stdlib2 | 312 | 16 | * control over rounding to meet legal or regulatory requirements,
* tracking of significant decimal places, or
* applications where the user expects the results to match calculations done by
hand.
For example, calculating a 5% tax on a 70 cent phone charge gives different
results in decimal floating point and binary... | large_dataset/raw/docs/python/stdlib2/stdlib2_312.md |
05c3e7dd-5ef5-5349-8cd1-027b2666bd43 | docs | python | python_stdlib2 | 312 | 17 | Exact representation enables the [`Decimal`](../library/decimal.html#decimal.Decimal "decimal.Decimal") class to perform
modulo calculations and equality tests that are unsuitable for binary floating
point:
```None
>>> Decimal('1.00') % Decimal('.10')
Decimal('0.00')
>>> 1.00 % 0.10
0.09999999999999995
>>> sum([Decim... | large_dataset/raw/docs/python/stdlib2/stdlib2_312.md |
5ca3675a-7ad8-5bf6-968a-ab031fcb1bf0 | docs | python | python_stdlib2 | 313 | 0 | # 11.Brief Tour of the Standard Library — Part II¶
Source: https://docs.python.org/3.13/tutorial/stdlib2.html
Version: 3.13
This second tour covers more advanced modules that support professional
programming needs. These modules rarely occur in small scripts.
## 11.1. Output Formatting[¶](#output-formatting "Link to... | large_dataset/raw/docs/python/stdlib2/stdlib2_313.md |
9cb87e6f-1fe9-53ce-842d-9570686bbafc | docs | python | python_stdlib2 | 313 | 1 | When the result is longer than one line, the “pretty printer” adds line breaks
and indentation to more clearly reveal data structure:
```None
>>> import pprint
>>> t = [[[['black', 'cyan'], 'white', ['green', 'red']], [['magenta',
... 'yellow'], 'blue']]]
...
>>> pprint.pprint(t, width=30)
[[[['black', 'cyan'],
... | large_dataset/raw/docs/python/stdlib2/stdlib2_313.md |
6544d5cd-de68-5834-a0f1-e80b71b6e3e9 | docs | python | python_stdlib2 | 313 | 2 | The [`locale`](../library/locale.html#module-locale "locale: Internationalization services.") module accesses a database of culture specific data formats.
The grouping attribute of locale’s format function provides a direct way of
formatting numbers with group separators:
```None
>>> import locale
>>> locale.setlocale... | large_dataset/raw/docs/python/stdlib2/stdlib2_313.md |
a402ba16-a412-591b-bb4e-82c22bb2ff0f | docs | python | python_stdlib2 | 313 | 3 | to customize their applications without having to alter the application.
The format uses placeholder names formed by `$` with valid Python identifiers
(alphanumeric characters and underscores). Surrounding the placeholder with
braces allows it to be followed by more alphanumeric letters with no intervening
spaces. Wri... | large_dataset/raw/docs/python/stdlib2/stdlib2_313.md |
f1bfc90f-19ea-5c11-bc39-3b6764d04f6d | docs | python | python_stdlib2 | 313 | 4 | [`safe_substitute()`](../library/string.html#string.Template.safe_substitute "string.Template.safe_substitute") method may be more appropriate —
it will leave placeholders unchanged if data is missing:
```None
>>> t = Template('Return the $item to $owner.')
>>> d = dict(item='unladen swallow')
>>> t.substitute(d)
Trac... | large_dataset/raw/docs/python/stdlib2/stdlib2_313.md |
aef6644d-71d0-5da2-b853-bc2cf09a61e3 | docs | python | python_stdlib2 | 313 | 5 | >>> for i, filename in enumerate(photofiles):
... base, ext = os.path.splitext(filename)
... newname = t.substitute(d=date, n=i, f=ext)
... print('{0} --> {1}'.format(filename, newname))
img_1074.jpg --> Ashley_0.jpg
img_1076.jpg --> Ashley_1.jpg
img_1077.jpg --> Ashley_2.jpg
```
Another application for t... | large_dataset/raw/docs/python/stdlib2/stdlib2_313.md |
2fd4ae90-1dd3-533b-bd34-4373f53dfd65 | docs | python | python_stdlib2 | 313 | 6 | how to loop through header information in a ZIP file without using the
[`zipfile`](../library/zipfile.html#module-zipfile "zipfile: Read and write ZIP-format archive files.") module. Pack codes `"H"` and `"I"` represent two and four
byte unsigned numbers respectively. The `"<"` indicates that they are
standard size and... | large_dataset/raw/docs/python/stdlib2/stdlib2_313.md |
cdbdf6f3-a1f4-53ef-a3ff-439698f068f5 | docs | python | python_stdlib2 | 313 | 7 | ## 11.4. Multi-threading[¶](#multi-threading "Link to this heading")
Threading is a technique for decoupling tasks which are not sequentially
dependent. Threads can be used to improve the responsiveness of applications
that accept user input while other tasks run in the background. A related use
case is running I/O in... | large_dataset/raw/docs/python/stdlib2/stdlib2_313.md |
152309c9-9425-53f1-81d4-0c043c9a70d8 | docs | python | python_stdlib2 | 313 | 8 | background = AsyncZip('mydata.txt', 'myarchive.zip')
background.start()
print('The main program continues to run in foreground.')
background.join() # Wait for the background task to finish
print('Main program waited until background was done.')
```
The principal challenge of multi-threaded applications is coordina... | large_dataset/raw/docs/python/stdlib2/stdlib2_313.md |
671c790f-af80-5104-aebb-7e148a1cd0da | docs | python | python_stdlib2 | 313 | 9 | coordination are easier to design, more readable, and more reliable.
## 11.5. Logging[¶](#logging "Link to this heading")
The [`logging`](../library/logging.html#module-logging "logging: Flexible event logging system for applications.") module offers a full featured and flexible logging system.
At its simplest, log m... | large_dataset/raw/docs/python/stdlib2/stdlib2_313.md |
bdf44237-82cd-55a0-ae33-e57f988a9d7c | docs | python | python_stdlib2 | 313 | 10 | through email, datagrams, sockets, or to an HTTP Server. New filters can select
different routing based on message priority: [`DEBUG`](../library/logging.html#logging.DEBUG "logging.DEBUG"),
[`INFO`](../library/logging.html#logging.INFO "logging.INFO"), [`WARNING`](../library/logging.html#logging.WARNING "logging.WARNI... | large_dataset/raw/docs/python/stdlib2/stdlib2_313.md |
95863149-1173-5965-92cb-c8c01ae47601 | docs | python | python_stdlib2 | 313 | 11 | This approach works fine for most applications but occasionally there is a need
to track objects only as long as they are being used by something else.
Unfortunately, just tracking them creates a reference that makes them permanent.
The [`weakref`](../library/weakref.html#module-weakref "weakref: Support for weak refer... | large_dataset/raw/docs/python/stdlib2/stdlib2_313.md |
2862f97d-62c8-5ecc-abc6-ff928715b94a | docs | python | python_stdlib2 | 313 | 12 | >>> d['primary'] # fetch the object if it is still alive
10
>>> del a # remove the one reference
>>> gc.collect() # run garbage collection right away
0
>>> d['primary'] # entry was automatically removed
Traceback (most recent call last):
File "<stdin>... | large_dataset/raw/docs/python/stdlib2/stdlib2_313.md |
3b360132-9bc9-5ad9-aa26-c0ea4595f867 | docs | python | python_stdlib2 | 313 | 13 | a list that stores only homogeneous data and stores it more compactly. The
following example shows an array of numbers stored as two byte unsigned binary
numbers (typecode `"H"`) rather than the usual 16 bytes per entry for regular
lists of Python int objects:
```None
>>> from array import array
>>> a = array('H', [40... | large_dataset/raw/docs/python/stdlib2/stdlib2_313.md |
ea0d3e7b-4ba1-5910-a230-007c4f1b103f | docs | python | python_stdlib2 | 313 | 14 | def breadth_first_search(unsearched):
node = unsearched.popleft()
for m in gen_moves(node):
if is_goal(m):
return m
unsearched.append(m)
```
In addition to alternative list implementations, the library also offers other
tools such as the [`bisect`](../library/bisect.html#module-bise... | large_dataset/raw/docs/python/stdlib2/stdlib2_313.md |
f60b6e28-123a-57a6-b512-d01121e3c941 | docs | python | python_stdlib2 | 313 | 15 | ```None
>>> from heapq import heapify, heappop, heappush
>>> data = [1, 3, 5, 7, 9, 2, 4, 6, 8, 0]
>>> heapify(data) # rearrange the list into heap order
>>> heappush(data, -5) # add a new entry
>>> [heappop(data) for i in range(3)] # fetch the three smallest entries
[-5, 0, 1]
```... | large_dataset/raw/docs/python/stdlib2/stdlib2_313.md |
994c1b6a-4bb6-59bc-a49b-02f4d8534c53 | docs | python | python_stdlib2 | 313 | 16 | * control over rounding to meet legal or regulatory requirements,
* tracking of significant decimal places, or
* applications where the user expects the results to match calculations done by
hand.
For example, calculating a 5% tax on a 70 cent phone charge gives different
results in decimal floating point and binary... | large_dataset/raw/docs/python/stdlib2/stdlib2_313.md |
527d799d-11bc-5c2a-8a27-ec5558cfdee6 | docs | python | python_stdlib2 | 313 | 17 | Exact representation enables the [`Decimal`](../library/decimal.html#decimal.Decimal "decimal.Decimal") class to perform
modulo calculations and equality tests that are unsuitable for binary floating
point:
```None
>>> Decimal('1.00') % Decimal('.10')
Decimal('0.00')
>>> 1.00 % 0.10
0.09999999999999995
>>> sum([Decim... | large_dataset/raw/docs/python/stdlib2/stdlib2_313.md |
5ed1d933-e196-525c-a1e1-730f931592e0 | docs | python | python_stdlib2 | 314 | 0 | # 11.Brief Tour of the Standard Library — Part II¶
Source: https://docs.python.org/3.14/tutorial/stdlib2.html
Version: 3.14
This second tour covers more advanced modules that support professional
programming needs. These modules rarely occur in small scripts.
## 11.1. Output Formatting[¶](#output-formatting "Link to... | large_dataset/raw/docs/python/stdlib2/stdlib2_314.md |
9d620fa8-a577-5d83-bede-e590fcb9d79c | docs | python | python_stdlib2 | 314 | 1 | When the result is longer than one line, the “pretty printer” adds line breaks
and indentation to more clearly reveal data structure:
```None
>>> import pprint
>>> t = [[[['black', 'cyan'], 'white', ['green', 'red']], [['magenta',
... 'yellow'], 'blue']]]
...
>>> pprint.pprint(t, width=30)
[[[['black', 'cyan'],
... | large_dataset/raw/docs/python/stdlib2/stdlib2_314.md |
e0256e69-93d9-57c2-b251-f8b17841c491 | docs | python | python_stdlib2 | 314 | 2 | The [`locale`](../library/locale.html#module-locale "locale: Internationalization services.") module accesses a database of culture specific data formats.
The grouping attribute of locale’s format function provides a direct way of
formatting numbers with group separators:
```None
>>> import locale
>>> locale.setlocale... | large_dataset/raw/docs/python/stdlib2/stdlib2_314.md |
77d6def5-d224-55ba-98c9-26211310b990 | docs | python | python_stdlib2 | 314 | 3 | to customize their applications without having to alter the application.
The format uses placeholder names formed by `$` with valid Python identifiers
(alphanumeric characters and underscores). Surrounding the placeholder with
braces allows it to be followed by more alphanumeric letters with no intervening
spaces. Wri... | large_dataset/raw/docs/python/stdlib2/stdlib2_314.md |
b7ba1b52-831e-525b-aa16-f13104533216 | docs | python | python_stdlib2 | 314 | 4 | [`safe_substitute()`](../library/string.html#string.Template.safe_substitute "string.Template.safe_substitute") method may be more appropriate —
it will leave placeholders unchanged if data is missing:
```None
>>> t = Template('Return the $item to $owner.')
>>> d = dict(item='unladen swallow')
>>> t.substitute(d)
Trac... | large_dataset/raw/docs/python/stdlib2/stdlib2_314.md |
300ac362-156f-5831-925f-89cdcc4ac726 | docs | python | python_stdlib2 | 314 | 5 | >>> for i, filename in enumerate(photofiles):
... base, ext = os.path.splitext(filename)
... newname = t.substitute(d=date, n=i, f=ext)
... print('{0} --> {1}'.format(filename, newname))
img_1074.jpg --> Ashley_0.jpg
img_1076.jpg --> Ashley_1.jpg
img_1077.jpg --> Ashley_2.jpg
```
Another application for t... | large_dataset/raw/docs/python/stdlib2/stdlib2_314.md |
c0423bcb-1612-5dbe-9cf1-e2af8f9474b1 | docs | python | python_stdlib2 | 314 | 6 | how to loop through header information in a ZIP file without using the
[`zipfile`](../library/zipfile.html#module-zipfile "zipfile: Read and write ZIP-format archive files.") module. Pack codes `"H"` and `"I"` represent two and four
byte unsigned numbers respectively. The `"<"` indicates that they are
standard size and... | large_dataset/raw/docs/python/stdlib2/stdlib2_314.md |
e3b30516-3b9d-5be1-b9d8-8ca397843b69 | docs | python | python_stdlib2 | 314 | 7 | ## 11.4. Multi-threading[¶](#multi-threading "Link to this heading")
Threading is a technique for decoupling tasks which are not sequentially
dependent. Threads can be used to improve the responsiveness of applications
that accept user input while other tasks run in the background. A related use
case is running I/O in... | large_dataset/raw/docs/python/stdlib2/stdlib2_314.md |
29e29d30-9a94-532e-b234-755f2d42f79e | docs | python | python_stdlib2 | 314 | 8 | background = AsyncZip('mydata.txt', 'myarchive.zip')
background.start()
print('The main program continues to run in foreground.')
background.join() # Wait for the background task to finish
print('Main program waited until background was done.')
```
The principal challenge of multi-threaded applications is coordina... | large_dataset/raw/docs/python/stdlib2/stdlib2_314.md |
f2d6d80d-4347-5126-962a-ba5e66dc66fd | docs | python | python_stdlib2 | 314 | 9 | coordination are easier to design, more readable, and more reliable.
## 11.5. Logging[¶](#logging "Link to this heading")
The [`logging`](../library/logging.html#module-logging "logging: Flexible event logging system for applications.") module offers a full featured and flexible logging system.
At its simplest, log m... | large_dataset/raw/docs/python/stdlib2/stdlib2_314.md |
b8f013d6-6e1c-59d3-aef1-40b008162bcd | docs | python | python_stdlib2 | 314 | 10 | through email, datagrams, sockets, or to an HTTP Server. New filters can select
different routing based on message priority: [`DEBUG`](../library/logging.html#logging.DEBUG "logging.DEBUG"),
[`INFO`](../library/logging.html#logging.INFO "logging.INFO"), [`WARNING`](../library/logging.html#logging.WARNING "logging.WARNI... | large_dataset/raw/docs/python/stdlib2/stdlib2_314.md |
c759f858-a93c-5145-b12e-b6070bf9594b | docs | python | python_stdlib2 | 314 | 11 | This approach works fine for most applications but occasionally there is a need
to track objects only as long as they are being used by something else.
Unfortunately, just tracking them creates a reference that makes them permanent.
The [`weakref`](../library/weakref.html#module-weakref "weakref: Support for weak refer... | large_dataset/raw/docs/python/stdlib2/stdlib2_314.md |
337eaa2a-cd6a-5442-ad11-a2de044de076 | docs | python | python_stdlib2 | 314 | 12 | >>> d['primary'] # fetch the object if it is still alive
10
>>> del a # remove the one reference
>>> gc.collect() # run garbage collection right away
0
>>> d['primary'] # entry was automatically removed
Traceback (most recent call last):
File "<stdin>... | large_dataset/raw/docs/python/stdlib2/stdlib2_314.md |
747da2ce-0052-5a3f-b586-52529823fc29 | docs | python | python_stdlib2 | 314 | 13 | a list that stores only homogeneous data and stores it more compactly. The
following example shows an array of numbers stored as two byte unsigned binary
numbers (typecode `"H"`) rather than the usual 16 bytes per entry for regular
lists of Python int objects:
```None
>>> from array import array
>>> a = array('H', [40... | large_dataset/raw/docs/python/stdlib2/stdlib2_314.md |
ceafc39f-70a9-53f7-bc31-419c92584c56 | docs | python | python_stdlib2 | 314 | 14 | def breadth_first_search(unsearched):
node = unsearched.popleft()
for m in gen_moves(node):
if is_goal(m):
return m
unsearched.append(m)
```
In addition to alternative list implementations, the library also offers other
tools such as the [`bisect`](../library/bisect.html#module-bise... | large_dataset/raw/docs/python/stdlib2/stdlib2_314.md |
4e25a0cf-ff7b-5ba5-9cd8-3a6a986113ad | docs | python | python_stdlib2 | 314 | 15 | ```None
>>> from heapq import heapify, heappop, heappush
>>> data = [1, 3, 5, 7, 9, 2, 4, 6, 8, 0]
>>> heapify(data) # rearrange the list into heap order
>>> heappush(data, -5) # add a new entry
>>> [heappop(data) for i in range(3)] # fetch the three smallest entries
[-5, 0, 1]
```... | large_dataset/raw/docs/python/stdlib2/stdlib2_314.md |
91d7e017-0e5f-5419-9c5f-654b1dfd6f0a | docs | python | python_stdlib2 | 314 | 16 | * control over rounding to meet legal or regulatory requirements,
* tracking of significant decimal places, or
* applications where the user expects the results to match calculations done by
hand.
For example, calculating a 5% tax on a 70 cent phone charge gives different
results in decimal floating point and binary... | large_dataset/raw/docs/python/stdlib2/stdlib2_314.md |
9a86130d-0c28-5d45-a10a-25166c631396 | docs | python | python_stdlib2 | 314 | 17 | Exact representation enables the [`Decimal`](../library/decimal.html#decimal.Decimal "decimal.Decimal") class to perform
modulo calculations and equality tests that are unsuitable for binary floating
point:
```None
>>> Decimal('1.00') % Decimal('.10')
Decimal('0.00')
>>> 1.00 % 0.10
0.09999999999999995
>>> sum([Decim... | large_dataset/raw/docs/python/stdlib2/stdlib2_314.md |
51f88ff1-e038-5603-9879-c0138044f218 | docs | python | python_stdlib2 | 315 | 0 | # 11.Brief Tour of the Standard Library — Part II¶
Source: https://docs.python.org/3.15/tutorial/stdlib2.html
Version: 3.15
This second tour covers more advanced modules that support professional
programming needs. These modules rarely occur in small scripts.
## 11.1. Output Formatting[¶](#output-formatting "Link to... | large_dataset/raw/docs/python/stdlib2/stdlib2_315.md |
f76ae5d1-6a94-510d-bb48-5c84fa84188a | docs | python | python_stdlib2 | 315 | 1 | When the result is longer than one line, the “pretty printer” adds line breaks
and indentation to more clearly reveal data structure:
```None
>>> import pprint
>>> t = [[[['black', 'cyan'], 'white', ['green', 'red']], [['magenta',
... 'yellow'], 'blue']]]
...
>>> pprint.pprint(t, width=30)
[[[['black', 'cyan'],
... | large_dataset/raw/docs/python/stdlib2/stdlib2_315.md |
7a4b035a-d7d0-5ce8-8e5f-18c86c423896 | docs | python | python_stdlib2 | 315 | 2 | The [`locale`](../library/locale.html#module-locale "locale: Internationalization services.") module accesses a database of culture specific data formats.
The grouping attribute of locale’s format function provides a direct way of
formatting numbers with group separators:
```None
>>> import locale
>>> locale.setlocale... | large_dataset/raw/docs/python/stdlib2/stdlib2_315.md |
e36a55dc-d247-5166-85e7-3942c64ca6f5 | docs | python | python_stdlib2 | 315 | 3 | to customize their applications without having to alter the application.
The format uses placeholder names formed by `$` with valid Python identifiers
(alphanumeric characters and underscores). Surrounding the placeholder with
braces allows it to be followed by more alphanumeric letters with no intervening
spaces. Wri... | large_dataset/raw/docs/python/stdlib2/stdlib2_315.md |
4bf10ade-4aad-5ce9-9818-cbcd6f99e605 | docs | python | python_stdlib2 | 315 | 4 | [`safe_substitute()`](../library/string.html#string.Template.safe_substitute "string.Template.safe_substitute") method may be more appropriate —
it will leave placeholders unchanged if data is missing:
```None
>>> t = Template('Return the $item to $owner.')
>>> d = dict(item='unladen swallow')
>>> t.substitute(d)
Trac... | large_dataset/raw/docs/python/stdlib2/stdlib2_315.md |
735ee15f-ec4d-5670-9a0a-71a91031243e | docs | python | python_stdlib2 | 315 | 5 | >>> for i, filename in enumerate(photofiles):
... base, ext = os.path.splitext(filename)
... newname = t.substitute(d=date, n=i, f=ext)
... print('{0} --> {1}'.format(filename, newname))
img_1074.jpg --> Ashley_0.jpg
img_1076.jpg --> Ashley_1.jpg
img_1077.jpg --> Ashley_2.jpg
```
Another application for t... | large_dataset/raw/docs/python/stdlib2/stdlib2_315.md |
a3691277-99f4-5a0e-af47-8dee08c6aa1d | docs | python | python_stdlib2 | 315 | 6 | how to loop through header information in a ZIP file without using the
[`zipfile`](../library/zipfile.html#module-zipfile "zipfile: Read and write ZIP-format archive files.") module. Pack codes `"H"` and `"I"` represent two and four
byte unsigned numbers respectively. The `"<"` indicates that they are
standard size and... | large_dataset/raw/docs/python/stdlib2/stdlib2_315.md |
a61daad5-b7cd-5f77-a879-83b700590244 | docs | python | python_stdlib2 | 315 | 7 | ## 11.4. Multi-threading[¶](#multi-threading "Link to this heading")
Threading is a technique for decoupling tasks which are not sequentially
dependent. Threads can be used to improve the responsiveness of applications
that accept user input while other tasks run in the background. A related use
case is running I/O in... | large_dataset/raw/docs/python/stdlib2/stdlib2_315.md |
1f062a26-d2fb-5a3b-8c14-01b0032b4da5 | docs | python | python_stdlib2 | 315 | 8 | background = AsyncZip('mydata.txt', 'myarchive.zip')
background.start()
print('The main program continues to run in foreground.')
background.join() # Wait for the background task to finish
print('Main program waited until background was done.')
```
The principal challenge of multi-threaded applications is coordina... | large_dataset/raw/docs/python/stdlib2/stdlib2_315.md |
365dc423-2980-5ca5-97d4-7607e8910aa8 | docs | python | python_stdlib2 | 315 | 9 | coordination are easier to design, more readable, and more reliable.
## 11.5. Logging[¶](#logging "Link to this heading")
The [`logging`](../library/logging.html#module-logging "logging: Flexible event logging system for applications.") module offers a full featured and flexible logging system.
At its simplest, log m... | large_dataset/raw/docs/python/stdlib2/stdlib2_315.md |
bb173b1b-f7f8-5c1c-bf47-b47a465b3046 | docs | python | python_stdlib2 | 315 | 10 | through email, datagrams, sockets, or to an HTTP Server. New filters can select
different routing based on message priority: [`DEBUG`](../library/logging.html#logging.DEBUG "logging.DEBUG"),
[`INFO`](../library/logging.html#logging.INFO "logging.INFO"), [`WARNING`](../library/logging.html#logging.WARNING "logging.WARNI... | large_dataset/raw/docs/python/stdlib2/stdlib2_315.md |
7b920e05-cd22-5a12-af32-6ab7a44d24ff | docs | python | python_stdlib2 | 315 | 11 | This approach works fine for most applications but occasionally there is a need
to track objects only as long as they are being used by something else.
Unfortunately, just tracking them creates a reference that makes them permanent.
The [`weakref`](../library/weakref.html#module-weakref "weakref: Support for weak refer... | large_dataset/raw/docs/python/stdlib2/stdlib2_315.md |
a97cf966-6bef-54e1-9389-8dee4d05751a | docs | python | python_stdlib2 | 315 | 12 | >>> d['primary'] # fetch the object if it is still alive
10
>>> del a # remove the one reference
>>> gc.collect() # run garbage collection right away
0
>>> d['primary'] # entry was automatically removed
Traceback (most recent call last):
File "<stdin>... | large_dataset/raw/docs/python/stdlib2/stdlib2_315.md |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.