More general way of generating PyODBC queries as a dict?

stackoverflowuser95 at gmail.com stackoverflowuser95 at gmail.com
Wed May 22 05:31:57 EDT 2013


On Wednesday, May 22, 2013 9:33:18 AM UTC+10, Dennis Lee Bieber wrote:
> On Tue, 21 May 2013 10:27:07 -0700 (PDT), stackoverflowuser95 at gmail.com
> 
> declaimed the following in gmane.comp.python.general:
> 
> 
> 
> > 
> 
> > For example, when multiple tables are queried; some hackish lambdas are required to generate the resulting dictionary.
> 
> > 
> 
> > Can you think of some more general methods?
> 
> >
> 
> 	What about using the information from 
> 
> 
> 
> 		cursor.description
> 
> 
> 
> You did state PyODBC, did you not?
> 
> 
> 
> """
> 
> description
> 
> 
> 
> This read-only attribute is a list of 7-item tuples, each containing
> 
> (name, type_code, display_size, internal_size, precision, scale,
> 
> null_ok). pyodbc only provides values for name, type_code,
> 
> internal_size, and null_ok. The other values are set to None.  
> 
> """
> 
> -- 
> 
> 	Wulfraed                 Dennis Lee Bieber         AF6VN
> 
>         wlfraed at ix.netcom.com    HTTP://wlfraed.home.netcom.com/

YAY: `[{c[0]: v for (c, v) in zip(row.cursor_description, row)} for row in self.cursor.fetchall()]`



More information about the Python-list mailing list