I have been developing a small application in Python using the Web.py framework that does some simple PostgreSQL queries. I have noticed that the returned value contains a whole bunch of stuff which encapsulates the actual raw data.
The following code is supposed to query the value of name from the table todo
name = db.query("SELECT name FROM todo;")
but when I call…
return name[0]
The following is returned/printed…
<Storage {'name': u'Learn web.py'}>
The data is correct, the value is “Learn web.py”, but I was wondering if it was possible to just get the raw data, “Learn web.py” instead of all the other stuff. I could parse it, but I was wondering if there was a more correct way like name.rawdata() function that I am missing? I have tried name[1] which is “out-of-bounds”.
The
[0]selects the first row from the result. The.namegets thenamecolumn from the row.Additionally, rather than using
db.querywith a raw SQL string, I’d usedb.select:See the documentation for more information.