Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>A column is just printed by calling <code>str</code> on it. So, if you want to do something else, you have to convert each column into a string yourself* (since calling <code>str</code> on a string just returns the string).</p> <p>In your case, we have to turn every element of the outer list into strings in the format we want… which will itself require turning every element of each inner list into strings so we can join them up in some way. In general, in Python, to do something to every element of a sequence, you either call <code>map</code>, or you write a comprehension, so I'll do one of each.</p> <p>After your edits, it looks like you want comma-separated columns, and comma-space-separated values within the columns, but that's OK because you want the columns auto-quoted. That's easy.</p> <p>To join up the values with <code>', '</code>, you just call <code>', '.join()</code> on them.</p> <pre><code>def stringify_column_list(column_list): return ', '.join(str(value) for value in column_list) </code></pre> <p>The weird separator and quoting, you already know how to handle in the <code>writer</code>. So the only thing left is to call our formatting function on each column:</p> <pre><code>writer.writerow(map(stringify_column_list, list1)) writer.writerow(map(stringify_column_list, list2)) </code></pre> <hr> <p>You might even want to consider using the <code>csv</code> module again to create the column values. But this is probably overkill here.</p> <hr> <p>* Or into some other object with a <code>__str__</code> method that does what you want, but that's rarely worth doing.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload