diff options
author | Ezio Melotti <ezio.melotti@gmail.com> | 2012-09-15 02:52:36 (GMT) |
---|---|---|
committer | Ezio Melotti <ezio.melotti@gmail.com> | 2012-09-15 02:52:36 (GMT) |
commit | 711f093030ab1e9d87cda56c103e5bde4c8e9c66 (patch) | |
tree | 882b35e1c720acd45cd41e47bce94d9ca0b47490 | |
parent | 9b1c84b5861bf259e709b56b7a11824b114801c9 (diff) | |
parent | e34f8a943b35f646ba3b1b5ff1835e9b3b242402 (diff) | |
download | cpython-711f093030ab1e9d87cda56c103e5bde4c8e9c66.zip cpython-711f093030ab1e9d87cda56c103e5bde4c8e9c66.tar.gz cpython-711f093030ab1e9d87cda56c103e5bde4c8e9c66.tar.bz2 |
#15932: merge with 3.2.
-rw-r--r-- | Doc/library/csv.rst | 28 |
1 files changed, 15 insertions, 13 deletions
diff --git a/Doc/library/csv.rst b/Doc/library/csv.rst index 5d8368b..4f19cee 100644 --- a/Doc/library/csv.rst +++ b/Doc/library/csv.rst @@ -71,9 +71,10 @@ The :mod:`csv` module defines the following functions: A short usage example:: >>> import csv - >>> spamReader = csv.reader(open('eggs.csv', newline=''), delimiter=' ', quotechar='|') - >>> for row in spamReader: - ... print(', '.join(row)) + >>> with open('eggs.csv', newline='') as csvfile: + ... spamreader = csv.reader(csvfile, delimiter=' ', quotechar='|') + ... for row in spamreader: + ... print(', '.join(row)) Spam, Spam, Spam, Spam, Spam, Baked Beans Spam, Lovely Spam, Wonderful Spam @@ -99,11 +100,12 @@ The :mod:`csv` module defines the following functions: A short usage example:: - >>> import csv - >>> spamWriter = csv.writer(open('eggs.csv', 'w', newline=''), delimiter=' ', - ... quotechar='|', quoting=csv.QUOTE_MINIMAL) - >>> spamWriter.writerow(['Spam'] * 5 + ['Baked Beans']) - >>> spamWriter.writerow(['Spam', 'Lovely Spam', 'Wonderful Spam']) + import csv + with open('eggs.csv', 'w', newline='') as csvfile: + spamwriter = csv.writer(csvfile, delimiter=' ', + quotechar='|', quoting=csv.QUOTE_MINIMAL) + spamwriter.writerow(['Spam'] * 5 + ['Baked Beans']) + spamwriter.writerow(['Spam', 'Lovely Spam', 'Wonderful Spam']) .. function:: register_dialect(name[, dialect], **fmtparams) @@ -221,11 +223,11 @@ The :mod:`csv` module defines the following classes: An example for :class:`Sniffer` use:: - csvfile = open("example.csv") - dialect = csv.Sniffer().sniff(csvfile.read(1024)) - csvfile.seek(0) - reader = csv.reader(csvfile, dialect) - # ... process CSV file contents here ... + with open('example.csv') as csvfile: + dialect = csv.Sniffer().sniff(csvfile.read(1024)) + csvfile.seek(0) + reader = csv.reader(csvfile, dialect) + # ... process CSV file contents here ... The :mod:`csv` module defines the following constants: |