Reputation: 179
When I use Pythons csv
module, it shows me
"delimiter" must be an 1-character string"
My code is like this
sep = ","
srcdata = cStringIO.StringIO(wdata[1])
data = csv.reader(srcdata, delimiter=sep)
wdata[1]
is a string source.
How do I fix this problem?
Upvotes: 12
Views: 7062
Reputation: 24939
You most likely have from __future__ import unicode_literals
at the top of your module or you are using python 3.x+ You need to do something like this:
sep=b"," # notice the b before the "
srcdata=cStringIO.StringIO(wdata[1])
data = csv.reader(srcdata,delimiter=sep)
This tells Python that you want to represent ","
as a byte string instead of a unicode literal.
Upvotes: 31