Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You seem to be saying that your <code>evnt_list</code> is a dictionary whose keys are strings and whose values are lists of strings. If so, then the CSV-writing code you've given in your question will write a string representation of a Python list into the second column. When you read anything in from CSV, it will just be a string, so once again you'll have a string representation of your list. For example, if you have a cell that contains <code>"['event1', 'event2']"</code> you will be reading in a string whose first character (at position 0) is <code>[</code>, second character is <code>'</code>, third character is <code>e</code>, etc. (I don't think your <code>tmp[1]</code> is right; I think it is really <code>'</code>, not <code>e</code>.)</p> <p>It sounds like you want to reconstruct the Python object, in this case a list of strings. To do that, use <code>ast.literal_eval</code>:</p> <pre><code>import ast cell_string_value = "['event1', 'event2']" cell_object = ast.literal_eval(cell_string_value) </code></pre> <p>Incidentally, the reason to use <code>ast.literal_eval</code> instead of just <code>eval</code> is safety. <code>eval</code> allows arbitrary Python expressions and is thus a security risk.</p> <p>Also, what is the purpose of the CSV, if you want to get the list back as a list? Will people be reading it (in Excel or something)? If not, then you may want to simply save the <code>evnt_list</code> object using <code>pickle</code> or <code>json</code>, and not bother with the CSV at all.</p> <p><strong>Edit:</strong> I should have read more carefully; the data from <code>evnt_list</code> is being <em>appended</em> to the CSV, and neither <code>pickle</code> nor <code>json</code> is easily appendable. So I suppose CSV is a reasonable and lightweight way to accumulate the data. A full-blown database might be better, but that would not be as lightweight.</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. 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