[Edu-sig] More GnuMath stuff
kirby.urner at gmail.com
Thu Sep 4 22:34:04 CEST 2008
This code segment is a bit on the esoteric side but shows how a
generator, an iterable like a list comprehension, may be pressed into
service to populate an SQL table using pysqlite's executemany command.
cur = con.cursor()
gen = (
(str(v), rbf.Vset[v].x, rbf.Vset[v].y, rbf.Vset[v].z)
for v in rbf.Vset
if v in "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
cur.executemany("insert into Vectors(label, x, y, z) values (?, ?,
?, ?)", gen)
Note we're not using %-operator dictionary substitution, but question
marks, with iterator as second parameter, playing the role of
tuple-generator (fill in the blanks).
What this looks like after running, in terms of raw data, is 26
"points of interest" used to anchor the aforementioned
whole-number-volumed polyhedra, tetrahedron as unit:
kirby at dell:~$ sqlite3 gnugeom
SQLite version 3.4.2
Enter ".help" for instructions
sqlite> select * from Vectors;
Here's a related graphic from:
Using Polyhedra to Teach OOP
and Coordinate Geometry Concepts
Chapter 7: Playing with Python
by Kirby Urner
First posted: August 28, 1999
Last modified: September 1, 1999
A concept we're after here is primitive ORM (object-relational
mapping) in that we'll like have a Vector class, used to instantiate
each row of the Vectors table as a "vector object". Vector objects
support __add__ and scalar multiplication (__mul__), plus may have a
self.draw() method for outputting to VPython, or some text file in
preparation for rendering.
Of course the whole Polyhedron might well be a class, probably is.
I'm not saying there's a one-size-fits-all solution here, would
encourage groups of students to cobble together their own databases in
most cases, at least smallish ones, as half the fun is using CREATE
TABLE, defining the relationships.
Note that Vectors are included in some secondary school level
curricula, though that's been increasingly pushed to remedial college
as the universal college expectation begets grade / degree inflation.
Our purpose here is to give high schoolers more opportunities as
job-ready entrepreneurs per the LEP High model (a charter school in
Portland). Here's a paragraph I've shared with some of my
My angle is it's less the degree or credential that matters and more
the evidence of skills, something to brag about in a job interview,
that you know SQL, even though just fresh out of high school. I'm
aiming towards a local economy in which a high school degree might be
sufficient again, for some entry level job, with college and company
life really a lot congruent in future, as work/study people farm
themselves out to this or that training, including history and
geography when traveling to that region... ends up being very like a
college degree, but measured more in promotions within the company (an
old template, no original thinking here, except it all sounds kinda
retro, now that we take quasi-universal college for granted).
Those of you who've seen my Chicago talk (Pycon, on Showmedo), may
also remember TECC, another charter in the wannabe category, wondering
of all the spotlight on Wasilla with help Anna's cause at all.
So all the information you'd need to actually draw a Tetrahedron in
VPython could be garnered from some a SELECT statement such as the
sqlite> select m.shortname, f.facet_id, f.vertex_id, v.x, v.y, v.z
from polyhedra m, facets f, vectors v where m.shortname = f.shortname
and f.label = v.label and m.shortname = "tetra";
For those less familiar with SQLite 3, it gives you a MySQL-like
administrative environment with Pysqlite2 the SQLite3 driver (yeah,
confusing). You've got a pretty good implementation of SQL engine
syntax, so moving from this sandbox to something more robust is an
easy transition. Some low volume websites never need to make the
More information about the Edu-sig