[Tutor] Feedback on coding style

Dennis Lee Bieber wlfraed at ix.netcom.com
Mon May 9 17:51:00 EDT 2022


On Mon, 9 May 2022 12:51:27 -0700, Alex Kleider <alexkleider at gmail.com>
declaimed the following:

>Would you consider putting this code (or Dennis' version of it) on github?

	I don't "do" git/github. I do have Mercurial installed locally just to
allow me to track history of my fiddling around. As long as attribution is
maintained I have no concerns of what others may do with stuff I post on
this forum (how better to experiment than to start with something
functional and modify it?).

	I'd probably recommend that the first thing to change would be to
create that helper function so that 
-=-=-
    print("\tMaximum %s event(s)" % "SYSTOLIC")
    print("%-9s   %-30s   %-9s   %-9s   %-9s" %
          ("   ID", "        Datestamp", "Systolic", "Diastolic", "
Pulse"))
    print("%-9s   %-30s   %-9s   %-9s   %-9s" %
          ("=========", "=============================",
           "=========", "=========", "========="))
    for record in systolic:
        print("%9s   %-30s   %9s   %9s   %9s" %
              (record[0], record[1], record[2], record[3], record[4]))
    print()
-=-=-
becomes a simple

	generate_section("SYSTOLIC", systolic)

(and repeat for diastolic, pulse, date [latest event]). Second change would
then be to pass the output destination, changing all the print() calls into
dest.write() calls (with applicable addition of \n to the formats).

{Heh -- I just did create the helper in my version}



>
>I've never used sqlite but would be interested in continuing to follow
>this thread as well as learning how to use it and how to collaborate
>using git.
>

	Things to read: the Python DB-API PEP (for the general goals of the API
and some of the variations you may encounter if using other RDBMs), the
Python sqlite3 module documentation (for the features specific to SQLite3),
and the SQLite3 documentation itself https://www.sqlite.org/docs.html for
the underlying engine. 

	In particular you will want to read about SQLite3's data model
https://www.sqlite.org/datatype3.html (there are only TEXT, INTEGER, REAL,
and BLOB data types -- the DDL parser accepts most any RDBM data
declaration and maps them to the closest (char, varchar => TEXT, int,
integer, <anything with "int" in it> => INTEGER, float, double => REAL).
BUT it also does not throw an error if one provides something "invalid" --
it will freely accept "one" in an integer field, though obviously one can't
do things like avg() a column with such a value.

	And, of course, for anything significant, you'll want to study some
guide to database normalization (at least to 3rd Normal Form) along with a
good description of general SQL statements (unique/duplicate allowed
indices, foreign keys, constraints).



	SQLite3 is a "file server" engine -- every application links to the
engine and hence is accessing database files using the privileges of the
logged in user (vs "client/server" where the clients send commands to a
separately running server process, and only the server accesses database
files).


-- 
	Wulfraed                 Dennis Lee Bieber         AF6VN
	wlfraed at ix.netcom.com    http://wlfraed.microdiversity.freeddns.org/



More information about the Tutor mailing list