title: Convert a string to a list and back
body: <p>I feel like this is a strange request.
  I'm starting with a string, and then I run that through a function that process the string (many lines) and returns a list.
  This list contains timestamps, and text.  It's an LRC file, actually (Lyric with track time)</p>
  
  <p>I'm writing a few kodi (xmbc) modules, and it runs its own python interpreter.  I can share data between addons but only as strings. (setting them as a property in kodi)</p>
  
  <p>So, I have a list that I can convert to a string easily with str(), but I can't get it back into the same list that I can deal with.</p>
  
  <p>Some example text:</p>
  
  <pre><code>[01:45.17]&lt;i&gt;I cant remember anything
  [01:48.80]Cant tell if this is true or dream
  [01:52.29]Deep down inside I feel to scream
  [01:55.91]This terrible silence stops me
  </code></pre>
  
  <p>This comes back from my parser function as a list. In raw form looks like this:</p>
  
  <pre><code>[{'timestamp': dbus.Int64(105170L), 'id': dbus.UInt32(0L), 'text': 'I cant remember anything'}, {'timestamp': dbus.Int64(108800L), 'id': dbus.UInt32(1L), 'text': 'Cant tell if this is true or dream'}, {'timestamp': dbus.Int64(112290L), 'id': dbus.UInt32(2L), 'text': 'Deep down inside I feel to scream'}, {'timestamp': dbus.Int64(115910L), 'id': dbus.UInt32(3L), 'text': 'This terrible silence stops me'}]
  </code></pre>
  
  <p>Once I convert this to a string with str() it looks exactly like what is above as a string.</p>
  
  <p>Now, I want to get this string back into the original list form. So that I can do line by line processes on it, and reference the elements, as I can with the pre-converted list:</p>
  
  <pre><code>print line['text']
  print line['timestamp']
  </code></pre>
  
  <p>I've tried various things, but can't seem to get it back into a list I can loop through.</p>
  
  <p>I looked at <a href="https://docs.python.org/2/library/json.html" rel="nofollow noreferrer">json.dumps</a> ('lines' is the list):</p>
  
  <pre><code>lines_str=json.dumps(lines)
  newlines=json.dumps(lines_str)
  
  print newlines.__class__.__name__
  </code></pre>
  
  <p>But this tells me that lines is still a "str"
  So, I tried with eval:</p>
  
  <pre><code>lines_str=str(lines)
  newlines=eval(lines_str)
  </code></pre>
  
  <p>But eval doesn't like the string format:</p>
  
  <pre><code>Traceback (most recent call last):
    File "./l.py", line 33, in &lt;module&gt;
      newlines=eval(lines_str)
    File "&lt;string&gt;", line 1, in &lt;module&gt;
  </code></pre>
  
  <p>then I tried <a href="http://docs.python.org/library/ast.html#ast.literal_eval" rel="nofollow noreferrer">literal_eval</a> from the <a href="http://docs.python.org/library/ast.html" rel="nofollow noreferrer">ast</a> module:</p>
  
  <pre><code>lines_str=str(lines)
  newlines=ast.literal_eval(lines_str)
  </code></pre>
  
  <p>But that liked my string even less.</p>
  
  <pre><code>  File "/usr/lib/python2.7/ast.py", line 79, in _convert
      raise ValueError('malformed string')
  ValueError: malformed string
  </code></pre>
  
  <p>I could perform this task in one addon versus the other.  But in the spirit of design, I have a back-end that does the work, and the front-end that paints the pretty pictures.  I'd prefer to keep the work on the back-end and minimize loading modules and processes on the front-end piece.</p>