Using python csv writer without quotations

前端 未结 4 937
猫巷女王i
猫巷女王i 2020-12-31 11:47

I\'m trying to write a list of strings like below to a file separated by the given delimiter.

res = [u\'123\', u\'hello world\']

When I try

4条回答
  •  醉话见心
    2020-12-31 12:22

    Quoting behavior is controlled by the various quoting arguments provided to the writer (or set on the Dialect object if you prefer to do things that way). The default setting is QUOTE_MINIMAL, which will not produce the behavior you're describing unless a value contains your delimiter character, quote character, or line terminator character. Doublecheck your test data - [u'123', u'hello'] won't produce what you describe, but [u'123', u' hello'] would.

    You can specify QUOTE_NONE if you're sure that's the behavior you want, in which case it'll either try to escape instances of your delimiter character if you set an escape character, or raise an exception if you don't.

提交回复
热议问题