summaryrefslogtreecommitdiffstats
path: root/Doc/library/bz2.rst
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2020-12-01 09:51:12 (GMT)
committerGitHub <noreply@github.com>2020-12-01 09:51:12 (GMT)
commit04232de22951037bed292ad910a3179f0bc26dfb (patch)
treeadb562f7b5cb04060ac4b9447d37489930a264c8 /Doc/library/bz2.rst
parent1cc5c943c007b92116f06b3ec8e71f2a510d1898 (diff)
downloadcpython-04232de22951037bed292ad910a3179f0bc26dfb.zip
cpython-04232de22951037bed292ad910a3179f0bc26dfb.tar.gz
cpython-04232de22951037bed292ad910a3179f0bc26dfb.tar.bz2
Fix bz2 examples markup (GH-23580)
(cherry picked from commit 80a429eae95c15c2c2a6753376f2697c90c2b6b9) Co-authored-by: Andre Delfino <adelfino@gmail.com>
Diffstat (limited to 'Doc/library/bz2.rst')
-rw-r--r--Doc/library/bz2.rst8
1 files changed, 0 insertions, 8 deletions
diff --git a/Doc/library/bz2.rst b/Doc/library/bz2.rst
index 277de60..cb9af58 100644
--- a/Doc/library/bz2.rst
+++ b/Doc/library/bz2.rst
@@ -264,7 +264,6 @@ Below are some examples of typical usage of the :mod:`bz2` module.
Using :func:`compress` and :func:`decompress` to demonstrate round-trip compression:
>>> import bz2
-
>>> data = b"""\
... Donec rhoncus quis sapien sit amet molestie. Fusce scelerisque vel augue
... nec ullamcorper. Nam rutrum pretium placerat. Aliquam vel tristique lorem,
@@ -273,11 +272,9 @@ Using :func:`compress` and :func:`decompress` to demonstrate round-trip compress
... Aliquam pharetra lacus non risus vehicula rutrum. Maecenas aliquam leo
... felis. Pellentesque semper nunc sit amet nibh ullamcorper, ac elementum
... dolor luctus. Curabitur lacinia mi ornare consectetur vestibulum."""
-
>>> c = bz2.compress(data)
>>> len(data) / len(c) # Data compression ratio
1.513595166163142
-
>>> d = bz2.decompress(c)
>>> data == d # Check equality to original object after round-trip
True
@@ -285,7 +282,6 @@ Using :func:`compress` and :func:`decompress` to demonstrate round-trip compress
Using :class:`BZ2Compressor` for incremental compression:
>>> import bz2
-
>>> def gen_data(chunks=10, chunksize=1000):
... """Yield incremental blocks of chunksize bytes."""
... for _ in range(chunks):
@@ -308,7 +304,6 @@ while ordered, repetitive data usually yields a high compression ratio.
Writing and reading a bzip2-compressed file in binary mode:
>>> import bz2
-
>>> data = b"""\
... Donec rhoncus quis sapien sit amet molestie. Fusce scelerisque vel augue
... nec ullamcorper. Nam rutrum pretium placerat. Aliquam vel tristique lorem,
@@ -317,14 +312,11 @@ Writing and reading a bzip2-compressed file in binary mode:
... Aliquam pharetra lacus non risus vehicula rutrum. Maecenas aliquam leo
... felis. Pellentesque semper nunc sit amet nibh ullamcorper, ac elementum
... dolor luctus. Curabitur lacinia mi ornare consectetur vestibulum."""
-
>>> with bz2.open("myfile.bz2", "wb") as f:
... # Write compressed data to file
... unused = f.write(data)
-
>>> with bz2.open("myfile.bz2", "rb") as f:
... # Decompress data from file
... content = f.read()
-
>>> content == data # Check equality to original object after round-trip
True