Python csv reader multi-character quotechar?
<p>I am dealing with Concordance loadfiles and have to edit them and thus I am using Python for that. The columns are delimited by the pilcrow char <code>Â¶</code> and have <code>Ã¾</code> as the quotechar.</p>

<p>The problem is the quotechar, the csv module in python only accepts a single-char quote (there is no issue when I write a csv file).</p>

<p>Question: how can I read a CSV file in Python where the quotechar is multi-character?</p>

<p>Example of the CSV fle:</p>

<pre><code>Ã¾col_1Ã¾Â¶Ã¾col_2Ã¾Â¶Ã¾col_3Ã¾Â¶Ã¾col_4Ã¾
</code></pre>

<p>The Concordance file format is 8-bit encoded, and the <code>Â¶</code> and <code>Ã¾</code> characters are encoded in Latin-1, really. That means they are encoded to binary values 0xB6 and 0xFE, respectively.</p>

<p>The Python 2 <code>csv</code> module accepts those bytes quite happily:</p>

<pre><code>csv.reader(fileobj, delimiter='\xb6', quotechar='\xfe')
</code></pre>

<p>As usual for the <code>csv</code> module, make sure to open the file in binary mode to leave newline handling to the module.</p>

<p>In Python 3, open the file in text mode with <code>newline=''</code> and <code>encoding='latin1'</code>, and either use the above <code>\xhh</code> escapes or the actual characters, so <code>delimiter='Â¶', quotechar='Ã¾'</code>.</p>

python csv