🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.python
Article #291

Re: PSA/QUESTION: Porting Windows batch to Python for macOS/Linux users

#291
From: Lawrence D’Oliveiro
Date: Sun, 22 Nov 2026 07:18
38 lines
2935 bytes
On Sun, 22 Nov 2026 02:17:32 -0400, Maria Sophia wrote:

> What's different between the batch and python is mostly:
>  a. SQLite queries primarily use Python's built-in sqlite3 module.

I like this alternative <https://rogerbinns.github.io/apsw> to the
standard-library sqlite module.

Pros and cons: <https://rogerbinns.github.io/apsw/pysqlite.html>.

When doing lots of database queries, I find a function like the
following very useful for handling the repetitive chores of 1)
creating a cursor, 2) executing a query on the cursor, 3) fetching the
results, and 4) disposing of the cursor. APSW version:

    def db_iter(conn, cmd, values = None, 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, values) :
            yield mapfn(item)
        #end for
    #end db_iter

Standard-library sqlite version:

    def db_iter(conn, cmd, values = (), 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, values) :
            yield mapfn(item)
        #end for
    #end db_iter

> As a result of the rewrite, I'm beginning to less-hate python since
> it's actually more intuitive than the Windows batch scripting was. :)

Surely *anything* would be more intuitive than Windows batch scripting
...
Technical Details
Message-ID: <11du4vq$o88b$1@dont-email.me>
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu!news.hispagatos.org!eternal-september.org!feeder.eternal-september.org!nntp.eternal-september.org!.POSTED!not-for-mail
References: <11dsuk8$2dgm$1@nnrp.usenet.blueworldhosting.com> <11dtk8d$2f73$1@nnrp.usenet.blueworldhosting.com> <11dtkua$3j5$1@nnrp.usenet.blueworldhosting.com> <11du1ds$2d2n$1@nnrp.usenet.blueworldhosting.com>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu!news.hispagatos.org!eternal-september.org!feeder.eternal-september.org!nntp.eternal-september.org!.POSTED!not-for-mail
From: Lawrence D’Oliveiro <ldo@nz.invalid>
Newsgroups: comp.lang.python,alt.os.linux,comp.sys.mac.system,alt.comp.os.windows-11
Subject: Re: PSA/QUESTION: Porting Windows batch to Python for macOS/Linux
 users
Date: Sun, 22 Nov 2026 07:18:19 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 38
Message-ID: <11du4vq$o88b$1@dont-email.me>
References: <11dsuk8$2dgm$1@nnrp.usenet.blueworldhosting.com>
	<11dtk8d$2f73$1@nnrp.usenet.blueworldhosting.com>
	<11dtkua$3j5$1@nnrp.usenet.blueworldhosting.com>
	<11du1ds$2d2n$1@nnrp.usenet.blueworldhosting.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Date: Sun, 22 Nov 2026 07:18:19 +0000 (UTC)
Injection-Info: dont-email.me;
	logging-data="794891"; mail-complaints-to="abuse@eternal-september.org";	posting-account="U2FsdGVkX1/OXp/kpVAonQ+0Pg6uyIhD"; posting-host="459210f3b638d87187d8a6c5f3a5794f"
User-Agent: Pan/0.165 (Kostiantynivka)
Cancel-Lock: sha1:BQ0W+2QUaFzfpBcslpAEzljyt1c= sha256:ksLsoI6mcjI+rm9eKKqhZRmKMmr06twXFjacFaEChFE=
	sha1:F5JCvkysI7Anz66DzZf849pHYPo= sha256:ff8nYEu6W0xP3qaQTkeqZs4s/L3qI0zT/bFnPoKSA6M=