I'm struggling to write numbers (0-10) into a CSV file. How do I change into a list, convert to integers, and have the number on each line?
<h1>Writes numbers from 0 to 10 into a CSV file</h1>

<p>import csv</p>

<pre><code>fileW = open('numbers.csv', 'w')
fileW.write('0,')
fileW.write('\n1,')
fileW.write('\n2,')
fileW.write('\n3,')
fileW.write('\n4,')
fileW.write('\n5')
fileW.write('\n6,')
fileW.write('\n7,')
fileW.write('\n8,')
fileW.write('\n9,')
fileW.write('\n10')
fileW.close();
</code></pre>

<h1>Read the numbers into a list</h1>

<pre><code>fileR = open('numbers.csv')
contnts = fileR.read()
print(contents)
</code></pre>

<p>This is my code. How do I convert this into integers and change into a list so that when I print the contents I got one column of numbers: one number on each line like [0 on first line, 1 on second line, 2 on third line...]?</p>

<p>What you want is the Python "csv" module  <a href="https://docs.python.org/2/library/csv.html" rel="nofollow">https://docs.python.org/2/library/csv.html</a>.  This makes it extremely easy to read and write CSV format.  For example,</p>

<pre><code>import csv
import sys

writer = csv.writer(sys.stdout)
writer.writerow([1, 2, 3])
</code></pre>

<p>With the csv module you can do many things easily, reading as well as writing, and this includes reading a whole CSV file pretty much in one gulp.</p>

python