From: Gerhard H. <gh...@gh...> - 2004-11-04 08:59:25
|
On Thu, Nov 04, 2004 at 04:26:26PM +1000, Timothy Smith wrote: > Hello, when i use fetch all i have a problem with what s returned. > everything is returned as this string ['data'] which makes is very > inconvienent to work it. is there better way of fetching things then > i am using? here is my code >=20 > cur =3D db.cursor() > cur.execute("SELECT UserGroup FROM UserMenuInfo WHERE UserName =3D UserNa= me") > groups =3D cur.fetchone() The DB-API requires that the return value of the fetchXX methods is a sequence. So even if you only select one column, you still get a sequence of length 1. To access the columns in the sequence, you can use index-based access: groups[0]. This will work with all database adapters. Much more convenient, but not portable is pyPgSQL's extension to access columns in the result row by name. Two ways to do this are supported, dictionary-style and attribute-style: groups["UserGroup"] groups.UserGroup HTH, -- Gerhard --=20 A: Because it messes up the order in which people normally read text. Q: Why is top-posting such a bad thing? A: Top-posting. Q: What is the most annoying thing on usenet and in e-mail? |