CSV delimiter doesn't work properly [Python]
<pre><code>import csv

base='eest1@mail.ru,username1\
test2@gmail.com,username2\
test3@gmail.com,username3\
test4@rambler.ru,username4\
test5@ya.ru,username5'

parsed=csv.reader(base, delimiter=',')
for p in parsed:
    print p
</code></pre>

<p>Returns:</p>

<pre><code>['e']
['e']
['s']
['t']
['1']
['@']
['m']
['a']
['i']
['l']
['.']
['r']
['u']
['', ''] 
</code></pre>

<p>etc...</p>

<p>How I can get data separated by comma ?
('test1@gmail.com', 'username1'),
('test2@gmail.com', 'username2'),
...</p>

<p>I think csv only works with file like objects.  You can use StringIO in this case.</p>

<pre><code>import csv
import StringIO

base='''eest1@mail.ru,username
test2@gmail.com,username2
test3@gmail.com,username3
test4@rambler.ru,username4
test5@ya.ru,username5'''

parsed=csv.reader(StringIO.StringIO(base), delimiter=',')
for p in parsed:
    print p
</code></pre>

<p>OUTPUT</p>

<pre><code>['eest1@mail.ru', 'username']
['test2@gmail.com', 'username2']
['test3@gmail.com', 'username3']
['test4@rambler.ru', 'username4']
['test5@ya.ru', 'username5']
</code></pre>

<p>Also, your example string does not have newlines, so you would get</p>

<pre><code>['eest1@mail.ru', 'usernametest2@gmail.com', 'username2test3@gmail.com', 'username3test4@rambler.ru', 'username4test5@ya.ru', 'username5']
</code></pre>

<p>You can use the <code>'''</code> like I did, or change your <code>base</code> like</p>

<pre><code>base='eest1@mail.ru,username\n\
test2@gmail.com,username2\n\
test3@gmail.com,username3\n\
test4@rambler.ru,username4\n\
test5@ya.ru,username5'
</code></pre>

<p><strong>EDIT</strong><br>
According to the docs, the argument can be either a file-like objet OR a list.  So this works too</p>

<pre><code>parsed=csv.reader(base.splitlines(), delimiter=',')
</code></pre>

python csv