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

    From Lawrence D?Oliveiro@3:633/10 to All on Sunday, November 22, 2026 07:18:19
    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
    ...

    --- PyGate Linux v1.5.19
    * Origin: Dragon's Lair, PyGate NNTP<>Fido Gate (3:633/10)