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


Groups > comp.lang.python > #78515

Re: Using namedtuple with sqlite, surely it can do better than the example

Path csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed1a.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <python-python-list@m.gmane.org>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.001
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'from:addr:yahoo.co.uk': 0.04; 'cursor': 0.09; 'lawrence': 0.09; 'pointless': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'language.': 0.14; 'bit)': 0.16; 'both,': 0.16; 'csv': 0.16; 'namedtuple': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'sqlite': 0.16; 'subject: \n ': 0.16; 'tuple': 0.16; 'language': 0.16; 'wrote:': 0.18; 'variable': 0.18; 'trying': 0.19; 'example': 0.22; 'import': 0.22; 'print': 0.22; 'header :User-Agent:1': 0.23; 'title,': 0.24; "i've": 0.25; 'least': 0.26; 'header:X-Complaints-To:1': 0.27; 'header:In-Reply-To:1': 0.27; "i'm": 0.30; 'department,': 0.31; 'url:python': 0.33; 'subject:the': 0.34; 'subject:with': 0.35; 'skip:s 30': 0.35; 'but': 0.35; 'otherwise.': 0.36; 'surely': 0.36; 'possible': 0.36; 'url:org': 0.36; 'should': 0.36; 'url:library': 0.38; 'to:addr :python-list': 0.38; 'rather': 0.38; 'subject:can': 0.39; 'sure': 0.39; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'easy': 0.60; 'url:3': 0.61; "you're": 0.61; 'our': 0.64; 'between': 0.67; 'subject:Using': 0.84
X-Injected-Via-Gmane http://gmane.org/
To python-list@python.org
From Mark Lawrence <breamoreboy@yahoo.co.uk>
Subject Re: Using namedtuple with sqlite, surely it can do better than the example
Date Wed, 01 Oct 2014 00:23:36 +0100
References <n3krfb-mo1.ln1@chris.zbmc.eu>
Mime-Version 1.0
Content-Type text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding 7bit
X-Gmane-NNTP-Posting-Host host-78-147-31-76.as13285.net
User-Agent Mozilla/5.0 (Windows NT 6.3; WOW64; rv:31.0) Gecko/20100101 Thunderbird/31.1.2
In-Reply-To <n3krfb-mo1.ln1@chris.zbmc.eu>
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.14500.1412119443.18130.python-list@python.org> (permalink)
Lines 31
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1412119445 news.xs4all.nl 2944 [2001:888:2000:d::a6]:43974
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:78515

Show key headers only | View raw


On 30/09/2014 22:32, cl@isbd.net wrote:
> In the namedtuple documentation there's an example:-
>
>      EmployeeRecord = namedtuple('EmployeeRecord', 'name, age, title, department, paygrade')
>
>      import sqlite3
>      conn = sqlite3.connect('/companydata')
>      cursor = conn.cursor()
>      cursor.execute('SELECT name, age, title, department, paygrade FROM employees')
>      for emp in map(EmployeeRecord._make, cursor.fetchall()):
>          print emp.name, emp.title
>
> (I've deleted the csv bit)
>
> Surely having to match up the "name, age, title, department,
> paygrade" between the tuple and the database can be automated, the
> example is rather pointless otherwise.  At the very least one should
> use the same variable instance for both, but it should be possible to
> get the tuple names from the database.
>

I'm not sure what you're trying to achieve but I've found it easy to use 
the sqlite Row object see 
https://docs.python.org/3/library/sqlite3.html#row-objects

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

Mark Lawrence

Back to comp.lang.python | Previous | Next — Previous in thread | Find similar | Unroll thread


Thread

Using namedtuple with sqlite, surely it can do better than the example cl@isbd.net - 2014-09-30 22:32 +0100
  Re: Using namedtuple with sqlite, surely it can do better than the example Peter Otten <__peter__@web.de> - 2014-10-01 01:06 +0200
  Re: Using namedtuple with sqlite, surely it can do better than the example Mark Lawrence <breamoreboy@yahoo.co.uk> - 2014-10-01 00:23 +0100

csiph-web