8000 *sigh* - i don't like this workflow at all · python/cpython@b7d1aeb · GitHub
[go: up one dir, main page]

Skip to content

Commit b7d1aeb

Browse files
author
Skip Montanaro
committed
*sigh* - i don't like this workflow at all
1 parent 482e7e0 commit b7d1aeb

File tree

1 file changed

+0
-52
lines changed

1 file changed

+0
-52
lines changed

Doc/library/csv.rst

Lines changed: 0 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -418,101 +418,50 @@ Examples
418418

419419
The simplest example of reading a CSV file::
420420

421-
<<<<<<< local
422-
import csv
423-
with f = open("some.csv", newline=''):
424-
reader = csv.reader(f)
425-
for row in reader:
426-
print(row)
427-
=======
428421
import csv
429422
with open('some.csv', newline='') as f:
430423
reader = csv.reader(f)
431424
for row in reader:
432425
print(row)
433-
>>>>>>> other
434426

435427
Reading a file with an alternate format::
436428

437-
<<<<<<< local
438-
import csv
439-
with f = open("passwd"):
440-
reader = csv.reader(f, delimiter=':', quoting=csv.QUOTE_NONE)
441-
for row in reader:
442-
print(row)
443-
=======
444429
import csv
445430
with open('passwd') as f:
446431
reader = csv.reader(f, delimiter=':', quoting=csv.QUOTE_NONE)
447432
for row in reader:
448433
print(row)
449-
>>>>>>> other
450434

451435
The corresponding simplest possible writing example is::
452436

453-
<<<<<<< local
454-
import csv
455-
with f = open("some.csv", "w"):
456-
writer = csv.writer(f)
457-
writer.writerows(someiterable)
458-
=======
459437
import csv
460438
with open('some.csv', 'w') as f:
461439
writer = csv.writer(f)
462440
writer.writerows(someiterable)
463-
>>>>>>> other
464441

465442 10000
Since :func:`open` is used to open a CSV file for reading, the file
466443
will by default be decoded into unicode using the system default
467444
encoding (see :func:`locale.getpreferredencoding`). To decode a file
468445
using a different encoding, use the ``encoding`` argument of open::
469446

470-
<<<<<<< local
471-
import csv
472-
f = open("some.csv", newline='', encoding='utf-8'):
473-
reader = csv.reader(f)
474-
for row in reader:
475-
print(row)
476-
=======
477447
import csv
478448
with open('some.csv', newline='', encoding='utf-8') as f:
479449
reader = csv.reader(f)
480450
for row in reader:
481451
print(row)
482-
>>>>>>> other
483452

484453
The same applies to writing in something other than the system default
485454
encoding: specify the encoding argument when opening the output file.
486455

487456
Registering a new dialect::
488457

489-
<<<<<<< local
490-
import csv
491-
csv.register_dialect('unixpwd', delimiter=':', quoting=csv.QUOTE_NONE)
492-
with f = open("passwd"):
493-
reader = csv.reader(f, 'unixpwd')
494-
for row in reader:
495-
pass
496-
=======
497458
import csv
498459
csv.register_dialect('unixpwd', delimiter=':', quoting=csv.QUOTE_NONE)
499460
with open('passwd') as f:
500461
reader = csv.reader(f, 'unixpwd')
501-
>>>>>>> other
502462

503463
A slightly more advanced use of the reader --- catching and reporting errors::
504464 CB0B

505-
<<<<<<< local
506-
import csv, sys
507-
filename = "some.csv"
508-
with f = open(filename, newline=''):
509-
reader = csv.reader(f)
510-
try:
511-
for row in reader:
512-
print(row)
513-
except csv.Error as e:
514-
sys.exit('file {}, line {}: {}'.format(filename, reader.line_num, e))
515-
=======
516465
import csv, sys
517466
filename = 'some.csv'
518467
with open(filename, newline='') as f:
@@ -522,7 +471,6 @@ A slightly more advanced use of the reader --- catching and reporting errors::
522471
print(row)
523472
except csv.Error as e:
524473
sys.exit('file {}, line {}: {}'.format(filename, reader.line_num, e))
525-
>>>>>>> other
526474

527475
And while the module doesn't directly support parsing strings, it can easily be
528476
done::

0 commit comments

Comments
 (0)
0