8

pymssql の結果から列名を取得する方法はありますか? as_dict=True を指定すると、すべての列ヘッダーを含むディクショナリが返されますが、それはディクショナリであるため、順序付けされていません。

4

4 に答える 4

16

pymssql は Python DB-API.descriptionをサポートすると主張しているため、カーソル オブジェクトから属性を取得できるはずです。

。説明

       This read-only attribute is a sequence of 7-item
       sequences.  

       Each of these sequences contains information describing
       one result column: 

         (name, 
          type_code, 
          display_size,
          internal_size, 
          precision, 
          scale, 
          null_ok)

したがって、「内部」シーケンスのそれぞれの最初の項目は、各列の名前です。

于 2011-03-04T05:27:20.970 に答える