Sujet : Re: The joy of FORTRAN
De : ldo (at) *nospam* nz.invalid (Lawrence D'Oliveiro)
Groupes : alt.folklore.computers comp.os.linux.miscDate : 27. Feb 2025, 22:50:05
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <vpqmmd$39d65$3@dont-email.me>
References : 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
User-Agent : Pan/0.162 (Pokrosvk)
On Thu, 27 Feb 2025 18:39:20 GMT, Charlie Gibbs wrote:
It wasn't that hard to write report programs in COBOL ...
Reports from ISAM files, to display devices using fixed-width fonts,
maybe; not so much from databases. or more readable-quality output.
COBOL could never match the simplicity of database accesses in a more
modern language, like Python:
def db_iter(conn, cmd, mapfn = lambda x : x) :
"executes cmd on a new cursor from connection conn and" \
" yields the results in turn."
for item in conn.cursor().execute(cmd, ()) :
yield mapfn(item)
#end for
#end db_iter
How to use?
list(db_iter
(
db,
"select name from planets order by name",
mapfn = lambda x : x[0]
))
Output:
['Jupiter', 'Mars', 'Mercury', 'Neptune', 'Saturn', 'Terra', 'Uranus', 'Venus']