views:

51

answers:

0

Is there a "Rosetta stone" which shows how to use Python tables of namedtuples in sqlite3 ? Say we have a namedtuple Row and a list or dict rows:

Row = namedtuple( "Row", "name city x y" )
rows = [None, Row( "Jones", "Boston", 3, 4 ), Row(...) ... ]

    # translate the following to sqlite please --

rows[id]
rows[id] = Row(...)
rows.append()
len(rows)
sorted( rows, key=mypythonfunc )
try: rows i.e. table exists
dump, load like pickle, load(dump(rows)) == rows
... your favourite idioms here.

Here rows may be a dict or a list, indexed by an id or key; thus its sql table has 5 columns, id name city x y. If it's a list, some of rows[id], e.g. rows[0], may be None.

Many of these translations are trivial, others are surely scattered around in various docs and snippets. A Rosetta stone, a table of basic translations all in one place, would help me. Links to concise SQL-in-Python doc / examples would be useful too.