Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
C
cpython
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
cpython
Commits
b7d1aebb
Kaydet (Commit)
b7d1aebb
authored
Mar 19, 2011
tarafından
Skip Montanaro
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
*sigh* - i don't like this workflow at all
üst
482e7e06
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
0 additions
and
52 deletions
+0
-52
csv.rst
Doc/library/csv.rst
+0
-52
No files found.
Doc/library/csv.rst
Dosyayı görüntüle @
b7d1aebb
...
@@ -418,101 +418,50 @@ Examples
...
@@ -418,101 +418,50 @@ Examples
The simplest example of reading a CSV file::
The simplest example of reading a CSV file::
<<<<<<< local
import csv
with f = open("some.csv", newline=''):
reader = csv.reader(f)
for row in reader:
print(row)
=======
import csv
import csv
with open('some.csv', newline='') as f:
with open('some.csv', newline='') as f:
reader = csv.reader(f)
reader = csv.reader(f)
for row in reader:
for row in reader:
print(row)
print(row)
>>>>>>> other
Reading a file with an alternate format::
Reading a file with an alternate format::
<<<<<<< local
import csv
with f = open("passwd"):
reader = csv.reader(f, delimiter=':', quoting=csv.QUOTE_NONE)
for row in reader:
print(row)
=======
import csv
import csv
with open('passwd') as f:
with open('passwd') as f:
reader = csv.reader(f, delimiter=':', quoting=csv.QUOTE_NONE)
reader = csv.reader(f, delimiter=':', quoting=csv.QUOTE_NONE)
for row in reader:
for row in reader:
print(row)
print(row)
>>>>>>> other
The corresponding simplest possible writing example is::
The corresponding simplest possible writing example is::
<<<<<<< local
import csv
with f = open("some.csv", "w"):
writer = csv.writer(f)
writer.writerows(someiterable)
=======
import csv
import csv
with open('some.csv', 'w') as f:
with open('some.csv', 'w') as f:
writer = csv.writer(f)
writer = csv.writer(f)
writer.writerows(someiterable)
writer.writerows(someiterable)
>>>>>>> other
Since :func:`open` is used to open a CSV file for reading, the file
Since :func:`open` is used to open a CSV file for reading, the file
will by default be decoded into unicode using the system default
will by default be decoded into unicode using the system default
encoding (see :func:`locale.getpreferredencoding`). To decode a file
encoding (see :func:`locale.getpreferredencoding`). To decode a file
using a different encoding, use the ``encoding`` argument of open::
using a different encoding, use the ``encoding`` argument of open::
<<<<<<< local
import csv
f = open("some.csv", newline='', encoding='utf-8'):
reader = csv.reader(f)
for row in reader:
print(row)
=======
import csv
import csv
with open('some.csv', newline='', encoding='utf-8') as f:
with open('some.csv', newline='', encoding='utf-8') as f:
reader = csv.reader(f)
reader = csv.reader(f)
for row in reader:
for row in reader:
print(row)
print(row)
>>>>>>> other
The same applies to writing in something other than the system default
The same applies to writing in something other than the system default
encoding: specify the encoding argument when opening the output file.
encoding: specify the encoding argument when opening the output file.
Registering a new dialect::
Registering a new dialect::
<<<<<<< local
import csv
csv.register_dialect('unixpwd', delimiter=':', quoting=csv.QUOTE_NONE)
with f = open("passwd"):
reader = csv.reader(f, 'unixpwd')
for row in reader:
pass
=======
import csv
import csv
csv.register_dialect('unixpwd', delimiter=':', quoting=csv.QUOTE_NONE)
csv.register_dialect('unixpwd', delimiter=':', quoting=csv.QUOTE_NONE)
with open('passwd') as f:
with open('passwd') as f:
reader = csv.reader(f, 'unixpwd')
reader = csv.reader(f, 'unixpwd')
>>>>>>> other
A slightly more advanced use of the reader --- catching and reporting errors::
A slightly more advanced use of the reader --- catching and reporting errors::
<<<<<<< local
import csv, sys
filename = "some.csv"
with f = open(filename, newline=''):
reader = csv.reader(f)
try:
for row in reader:
print(row)
except csv.Error as e:
sys.exit('file {}, line {}: {}'.format(filename, reader.line_num, e))
=======
import csv, sys
import csv, sys
filename = 'some.csv'
filename = 'some.csv'
with open(filename, newline='') as f:
with open(filename, newline='') as f:
...
@@ -522,7 +471,6 @@ A slightly more advanced use of the reader --- catching and reporting errors::
...
@@ -522,7 +471,6 @@ A slightly more advanced use of the reader --- catching and reporting errors::
print(row)
print(row)
except csv.Error as e:
except csv.Error as e:
sys.exit('file {}, line {}: {}'.format(filename, reader.line_num, e))
sys.exit('file {}, line {}: {}'.format(filename, reader.line_num, e))
>>>>>>> other
And while the module doesn't directly support parsing strings, it can easily be
And while the module doesn't directly support parsing strings, it can easily be
done::
done::
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment