[Newbie] Strange output from list
bignose+hates-spam at benfinney.id.au
Tue Nov 11 02:41:10 CET 2008
Gilles Ganault <nospam at nospam.com> writes:
> I'm getting some unwanted result when SELECTing data from an SQLite
> sql = 'SELECT id FROM master'
> for id in rows:
> sql = 'SELECT COUNT(code) FROM companies WHERE code="%s"' % id
> result = list(cursor.execute(sql))
> print "Code=%s, number=%s" % (id,result)
> Code=0111Z, number=(47,)
> I expected to see "number=47". Why does Python return "(47,)"?
The result of an SQL SELECT is a sequence of tuples, where each item
in the tuple is a value for a column as specified in the SELECT
SQLAlchemy represents this with a sequence of ResultProxy objects.
When you convert a ResultProxy object to a string, it displays like a
tuple. See the documentation for other ways of accessing various
attributes of a ResultProxy object.
\ “What is it that makes a complete stranger dive into an icy |
`\ river to save a solid gold baby? Maybe we'll never know.” —Jack |
_o__) Handey |
More information about the Python-list