I have the string "[u'foo']" (Yes, it includes square brackets and u'' ). I have to convert this to a list that looks like [u'foo'] .
"[u'foo']"
u''
[u'foo']
list("[u'foo']") will not work.
list("[u'foo']")
Any suggestions?
>>> import ast >>> s = "[u'foo']" >>> ast.literal_eval(s) [u'foo']
documentation
eval("[u'foo']", {'__builtins__':[]}, {})
Source: https://habr.com/ru/post/1386126/More articles:com.google.common.collect.Sets.SetView error or function? - javaMap request using JPA 2.0 criteria - javaMatching two patterns in one python regex, capturing only non-empty values - pythonconverting a string to a list of tuples - pythonvim: show diff on W11 (file changed since editing started) - vimParsing msg / eml files using Python 2.7 - pythonBold / Unallocated Rows in PyGTK TreeView - pythonuser creation and lack of privileges - sqlHow to make an alternative site language the default site language? - backendnode.js get socket file descriptor? - node.jsAll Articles