Skip to content

Commit 9978ce5

Browse files
Move writing examples up a little
1 parent b2a1f90 commit 9978ce5

File tree

1 file changed

+15
-15
lines changed

1 file changed

+15
-15
lines changed

Doc/library/tarfile.rst

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1325,6 +1325,21 @@ How to read a gzip compressed tar archive and display some member information::
13251325
Writing examples
13261326
~~~~~~~~~~~~~~~~
13271327

1328+
How to create an uncompressed tar archive from a list of filenames::
1329+
1330+
import tarfile
1331+
tar = tarfile.open("sample.tar", "w")
1332+
for name in ["foo", "bar", "quux"]:
1333+
tar.add(name)
1334+
tar.close()
1335+
1336+
The same example using the :keyword:`with` statement::
1337+
1338+
import tarfile
1339+
with tarfile.open("sample.tar", "w") as tar:
1340+
for name in ["foo", "bar", "quux"]:
1341+
tar.add(name)
1342+
13281343
How to create and write an archive to stdout using
13291344
:data:`sys.stdout.buffer <sys.stdout>` in the *fileobj* parameter
13301345
in :meth:`TarFile.add`::
@@ -1347,21 +1362,6 @@ parameter in :meth:`TarFile.add`::
13471362
tar.add("foo", filter=reset)
13481363
tar.close()
13491364

1350-
How to create an uncompressed tar archive from a list of filenames::
1351-
1352-
import tarfile
1353-
tar = tarfile.open("sample.tar", "w")
1354-
for name in ["foo", "bar", "quux"]:
1355-
tar.add(name)
1356-
tar.close()
1357-
1358-
The same example using the :keyword:`with` statement::
1359-
1360-
import tarfile
1361-
with tarfile.open("sample.tar", "w") as tar:
1362-
for name in ["foo", "bar", "quux"]:
1363-
tar.add(name)
1364-
13651365
.. _tar-formats:
13661366

13671367
Supported tar formats

0 commit comments

Comments
 (0)