Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The above code does not give <code>csv.writer.writerows</code> input that it expects. Specifically:</p> <pre><code>resultArray = results.split('\n') </code></pre> <p>This creates a list of strings. Then, you pass each string to your writer and tell it to writerows with it:</p> <pre><code>for row in resultArray: writer.writerows(row) </code></pre> <p>But <code>writerows</code> does not expect a single string. From the docs:</p> <blockquote> <p>csvwriter.writerows(rows)</p> <p>Write all the <code>rows</code> parameters (a list of row objects as described above) to the writer’s file object, formatted according to the current dialect.</p> </blockquote> <p>So you're passing a string to a method that expects its argument to be a list of row objects, where a row object is itself expected to be a sequence of strings or numbers:</p> <blockquote> <p>A row must be a sequence of strings or numbers for Writer objects</p> </blockquote> <p>Are you sure your listed example code accurately reflects your attempt? While it certainly won't work, I would expect the exception produced to be different.</p> <p>For a possible fix - if all you are trying to do is to write a big string to a file, you don't need the <code>csv</code> library at all. You can just write the string directly. Even splitting on newlines is unnecessary unless you need to do something like replacing Unix-style linefeeds with DOS-style linefeeds.</p> <p>If you need to use the <code>csv</code> module after all, you need to give your writer something it understands - in this example, that would be something like <code>writer.writerow(['A','bunch+of','multiline','CSV,LIKE,STRING'])</code>. Note that that's a true Python list of strings. If you need to turn your raw string <code>"'A','bunch+of','multiline','CSV,LIKE,STRING'"</code> into such a list, I think you'll find the <code>csv</code> library useful as a reader - no need to reinvent the wheel to handle the quoted commas in the substring 'CSV,LIKE,STRING'. And in that case you would need to care about your dialect.</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