Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #80415 > unrolled thread

What is description attribute in python?

Started bysatishmlmlml@gmail.com
First post2014-11-09 02:42 -0800
Last post2014-11-09 04:59 -0600
Articles 6 — 5 participants

Back to article view | Back to comp.lang.python


Contents

  What is description attribute in python? satishmlmlml@gmail.com - 2014-11-09 02:42 -0800
    Re: What is description attribute in python? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-11-09 21:59 +1100
      Re: What is description attribute in python? satishmlmlml@gmail.com - 2014-11-09 03:05 -0800
        Re: What is description attribute in python? Mark Lawrence <breamoreboy@yahoo.co.uk> - 2014-11-09 14:13 +0000
      Re: What is description attribute in python? Deepfriedice <Deepfriedice@openmailbox.org> - 2014-11-09 21:08 +1000
    Re: What is description attribute in python? Tim Chase <python.list@tim.thechases.com> - 2014-11-09 04:59 -0600

#80415 — What is description attribute in python?

Fromsatishmlmlml@gmail.com
Date2014-11-09 02:42 -0800
SubjectWhat is description attribute in python?
Message-ID<abfcf629-9c5a-4db0-a7bb-dd10e9bba098@googlegroups.com>
What does description attribute in the following code mean?

curs.execute('select * from people')
colnames = [desc[0] for desc in curs.description]

[toc] | [next] | [standalone]


#80418

FromSteven D'Aprano <steve+comp.lang.python@pearwood.info>
Date2014-11-09 21:59 +1100
Message-ID<545f48fc$0$13005$c3e8da3$5496439d@news.astraweb.com>
In reply to#80415
satishmlmlml@gmail.com wrote:

> What does description attribute in the following code mean?
> 
> curs.execute('select * from people')
> colnames = [desc[0] for desc in curs.description]

It's an attribute called "description". You would need to read the
documentation for curs to know what it does.

What is curs? Where does it come from?


-- 
Steven

[toc] | [prev] | [next] | [standalone]


#80419

Fromsatishmlmlml@gmail.com
Date2014-11-09 03:05 -0800
Message-ID<b89135f2-81d5-4e27-ab17-adda1d260343@googlegroups.com>
In reply to#80418
curs is coming from the following piece of code

import sqlite3
conn = sqlite3.connect('dbase1')
curs = conn.cursor()

[toc] | [prev] | [next] | [standalone]


#80431

FromMark Lawrence <breamoreboy@yahoo.co.uk>
Date2014-11-09 14:13 +0000
Message-ID<mailman.15599.1415542411.18130.python-list@python.org>
In reply to#80419
On 09/11/2014 11:05, satishmlmlml@gmail.com wrote:
> curs is coming from the following piece of code
>
> import sqlite3
> conn = sqlite3.connect('dbase1')
> curs = conn.cursor()
>

Today's exercise is to find the documentation and read it before posting 
another question.  Better still is to use the interactive prompt to run 
the above and the help facility at the same time. IMHO this is the best 
possible way to learn Python.

-- 
My fellow Pythonistas, ask not what our language can do for you, ask
what you can do for our language.

Mark Lawrence

[toc] | [prev] | [next] | [standalone]


#80421

FromDeepfriedice <Deepfriedice@openmailbox.org>
Date2014-11-09 21:08 +1000
Message-ID<m3nhuu$n3u$1@speranza.aioe.org>
In reply to#80418
On 09/11/14 20:59, Steven D'Aprano wrote:
> It's an attribute called "description". You would need to read the
> documentation for curs to know what it does.
>
> What is curs? Where does it come from?

It looks like a cursor from an SQL DB library.
For example, sqlite3 in the standard library provides a 
Cursor.description attribute:

https://docs.python.org/3/library/sqlite3.html#sqlite3.Cursor.description
 > This read-only attribute provides the column names of the last query. 
 > To remain compatible with the Python DB API, it returns a 7-tuple for 
 > each column where the last six items of each tuple are None.
 >
 > It is set for SELECT statements without any matching rows as well.

You'll have to read the documentation from the library you're using to 
determine what it actually does.

[toc] | [prev] | [next] | [standalone]


#80426

FromTim Chase <python.list@tim.thechases.com>
Date2014-11-09 04:59 -0600
Message-ID<mailman.15597.1415535253.18130.python-list@python.org>
In reply to#80415
On 2014-11-09 02:42, satishmlmlml@gmail.com wrote:
> What does description attribute in the following code mean?
> 
> curs.execute('select * from people')
> colnames = [desc[0] for desc in curs.description]

http://legacy.python.org/dev/peps/pep-0249/#cursor-attributes

-tkc



[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web