[Tutor] Counting MySQL Fields

Kent Johnson kent37 at tds.net
Sat Jun 11 13:04:39 CEST 2005


Don Parris wrote:
> I'd like to use the result.numfields() function to count the fields on a
> given table, but apparently don't quite grasp how to implement it.  Below is
> my lame attempt.  I searched the comp.lang.python group via Google, but
> didn't find any relevant info.  The MySQLdb User Guide didn't give an
> example, nor does the module source.
> 
> My attempt here was to retrieve a single row, and count the fields.  That
> obviously didn't work. If there's a good example of this, I'd appreciate a
> pointer.  If you can explain this operation a bit, that would be useful
> also.  I'm running SUSE Linux 9.2 Pro on an AMD box.  

>From a look at the DB-API docs I would think len(result) would give you what you want, or len(list(cursor.description))

Kent



More information about the Tutor mailing list