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


Groups > comp.lang.python > #78509

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

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!news.swapon.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From cl@isbd.net
Newsgroups comp.lang.python
Subject Using namedtuple with sqlite, surely it can do better than the example
Date Tue, 30 Sep 2014 22:32:07 +0100
Lines 22
Message-ID <n3krfb-mo1.ln1@chris.zbmc.eu> (permalink)
Mime-Version 1.0
Content-Type text/plain; charset=UTF-8
Content-Transfer-Encoding 8bit
X-Trace individual.net LhdC5JVeCGq0cwXrWG6qVg1TwkyfjzhkrzPTVRwR5Zm/CbJsA=
X-Orig-Path not-for-mail
Cancel-Lock sha1:5zcbAKa+xGsbU3t6j3MtEXawr9s=
User-Agent tin/2.2.0-20131224 ("Lochindaal") (UNIX) (Linux/3.13.0-36-generic (x86_64))
Xref csiph.com comp.lang.python:78509

Show key headers only | View raw


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.

-- 
Chris Green
ยท

Back to comp.lang.python | Previous | Next — Next 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