Browse Source

CSV

pull/44/head
Jure Šorn 5 years ago
parent
commit
a12f39bea5
2 changed files with 6 additions and 6 deletions
  1. 6
      README.md
  2. 6
      index.html

6
README.md

@ -1679,19 +1679,19 @@ b'.\n..\nfile1.txt\nfile2.txt\n'
CSV
---
```python
from csv import reader, writer
import csv
```
### Read
```python
<reader> = reader(<file>, dialect='excel', delimiter=',')
<reader> = csv.reader(<file>, dialect='excel', delimiter=',')
<list> = next(<reader>) # Returns next row as a list of strings.
```
* **File must be opened with `'newline=""'` argument, or newlines embedded inside quoted fields will not be interpreted correctly!**
### Write
```python
<writer> = writer(<file>, dialect='excel', delimiter=',')
<writer> = csv.writer(<file>, dialect='excel', delimiter=',')
<writer>.writerow(<collection>) # Encodes objects using `str(<el>)`.
<writer>.writerows(<coll_of_coll>)
```

6
index.html

@ -1512,17 +1512,17 @@ shutil.copytree(from, to) <span class="hljs-comment"># Copies the entir
<span class="hljs-number">0</span>
</code></pre></div>
<div><h2 id="csv"><a href="#csv" name="csv">#</a>CSV</h2><pre><code class="python language-python hljs"><span class="hljs-keyword">from</span> csv <span class="hljs-keyword">import</span> reader, writer
<div><h2 id="csv"><a href="#csv" name="csv">#</a>CSV</h2><pre><code class="python language-python hljs"><span class="hljs-keyword">import</span> csv
</code></pre></div>
<div><h3 id="read">Read</h3><pre><code class="python language-python hljs">&lt;reader&gt; = reader(&lt;file&gt;, dialect=<span class="hljs-string">'excel'</span>, delimiter=<span class="hljs-string">','</span>)
<div><h3 id="read">Read</h3><pre><code class="python language-python hljs">&lt;reader&gt; = csv.reader(&lt;file&gt;, dialect=<span class="hljs-string">'excel'</span>, delimiter=<span class="hljs-string">','</span>)
&lt;list&gt; = next(&lt;reader&gt;) <span class="hljs-comment"># Returns next row as a list of strings.</span>
</code></pre></div>
<ul>
<li><strong>File must be opened with <code class="python hljs"><span class="hljs-string">'newline=""'</span></code> argument, or newlines embedded inside quoted fields will not be interpreted correctly!</strong></li>
</ul>
<div><h3 id="write">Write</h3><pre><code class="python language-python hljs">&lt;writer&gt; = writer(&lt;file&gt;, dialect=<span class="hljs-string">'excel'</span>, delimiter=<span class="hljs-string">','</span>)
<div><h3 id="write">Write</h3><pre><code class="python language-python hljs">&lt;writer&gt; = csv.writer(&lt;file&gt;, dialect=<span class="hljs-string">'excel'</span>, delimiter=<span class="hljs-string">','</span>)
&lt;writer&gt;.writerow(&lt;collection&gt;) <span class="hljs-comment"># Encodes objects using `str(&lt;el&gt;)`.</span>
&lt;writer&gt;.writerows(&lt;coll_of_coll&gt;)
</code></pre></div>

Loading…
Cancel
Save