[Tutor] Writing to CSV string containing quote and comma
spir
denis.spir at gmail.com
Tue Dec 10 13:43:57 CET 2013
On 12/10/2013 12:46 AM, Steven D'Aprano wrote:
> In Python 2.7, you can abbreviate that last one slightly:
>
> '{} "{}"'.format(number, word)
Why 2.7? By me also works with 3.3.
> Either should be preferred to building the string by hand with + signs.
> The rule of thumb I use is to say that adding two substrings together is
> fine, if I need more than one + sign I use a format string. So these
> would be okay:
>
> plural = word + "s"
> line = sentence + '\n'
>
> but anything more complex and I would use % or format().
That's also my rule, except if I use %-strings or format around, I also use it
for a single, binary catenation.
Denis
More information about the Tutor
mailing list