i have users emails stored in database like this below.
['[email protected]','[email protected]','[email protected]']
I have to get each email of all users one by one. After querying i wrote the following code.
cur.execute("sql query")
rows = cur.fetchall()
for row in rows:
print row[2]
print type(row[2])
emails = json.loads(json.dumps(row[2]))
print type(emails)
<type 'str'>
<type 'unicode'>
it converts it into Unicode instead of list.
print row[2]and it prints all the list of emails as i show above. you can see in code that it says it is string.repr(row[2])produce?json.dumps()thenjson.loads()is not going to work, even if the row contained some kind of JSON data.json.dumps(something)produces a JSON encoding ofsomething, which you then decode again withjson.loads(). You just encoded to JSON and that encoding was then decoded again. The only thing that achieves is that you test if a string can be JSON encoded (it can) and the result is a Unicode string with the same contents as what you started with.