0

I use the csv.writer() to write some values to my file.
My delimiter is ";".

Now I want that the value pnr hast quotechars in the file - like:

1;12;2014;"110585";200;20.10.2014;;28.10.2014;N;;;
1;12;2014;"110603";200;06.10.2014;;07.10.2014;N;;;

I tried this:

pnr = '\"' + str(pnr) + '\"'

and got this traceback:

writer.writerow(l)
_csv.Error: need to escape, but no escapechar set

I know what it means but i do not have any solutions.

Grijesh Chauhan
  • 57,103
  • 20
  • 141
  • 208
JER
  • 39
  • 9
  • note: avoid `+` operator with strings e.g. do `'\"' + str(pnr) + '\"'` as `'"%s"' % pnr`. Btw, read this Q&A http://stackoverflow.com/a/11372673/1673391 if it answers you. – Grijesh Chauhan Dec 05 '14 at 05:39
  • @GrijeshChauhan - Or like the docs says '{}'.format(pnr) – Or Duan Dec 05 '14 at 05:47

0 Answers0