[Edu-sig] teaching Python 3.5 in 2016: snapshot

kirby urner kirby.urner at gmail.com
Mon Jul 18 17:30:30 EDT 2016


I'm prepping for class tomorrow, as a Python instructor for employed
adults eligible for California State funded professional development
electives, not for college credit but career-relevant nonetheless.

My approach is to use collections.namedtuple to show the tuple (a
sequence type, like a list) having its "slots" accessed via dot notation,
not just through indexing, then swapping in an equivalent class that
does the same thing (down to having __getitem__ in some
examples).

Seeing how a class duplicates features we've already introduced,
makes a nice bridge to "defining your own types" (vs using the
__builtins__ or standard library types).

Once with have dicts and lists introduced, near the start, we're
ready to talk about JSON already, which brings in early previews
of web services, APIs, inter-operability with JavaScript (ES) and
of course MongoDB.

I just use json module to store .json files, as soon as we get to the
function open( ), i.e. here's a first example of

Talking about Python in the context of getting between a browser
and a database or persistent storage, gets the juices flowing about
"an ecosystem".

These two source code files show off the web API angle, using
an open API to get IMDB information (movie database):

https://github.com/4dsolutions/Python5/blob/master/get_movie.py

https://github.com/4dsolutions/Python5/blob/master/get_movie_v2.py

Here's another example, going from namedtuple Element
(for Periodic Table atoms), to class-based Element:

namedtuple:

https://github.com/4dsolutions/Python5/blob/master/elements_02.py

class based:

https://github.com/4dsolutions/Python5/blob/master/elements_04.py

Actually running these would require the *.json files, both included in the
repo:

elements_v1.json
elements_v2.json

Next stop:  SQLite and try / except syntax.

Kirby

PS:  I'm pushing Pyret pretty seriously even though it's very much
the moving target.

Follow the action on Twitter @4DsolutionsPDX

python-cuba working group also going well.  Py2017 shaping up.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/edu-sig/attachments/20160718/e4809406/attachment.html>


More information about the Edu-sig mailing list