[Edu-sig] a next edition of a Python for adults course

kirby urner kirby.urner at gmail.com
Wed Jul 13 13:53:47 EDT 2016


I'm back to teaching another 5 week, 2-meetups/week
course for Saisoft.net based in Irvine, CA.  My students
are eligible for free professional development (PD) in
that state.  I don't think Oregon has anything similar,
not even for teachers.

This time, after going over tuple, list, dict, int and bool
in some detail, getting the ball rolling on data structures,
I turned to "the API economy" and JSON as now readable,
given our new knowledge of dicts and lists, and how
these embed inside each other to arbitrary depth.

I like using collections.namedtuple quite a bit, as a way
to set the stage for class semantics.  The namedtuple
is like an ordinary tuple but you get to name the elements
and refer to them with dot notation.

# -*- coding: utf-8 -*-
"""
Created on Thu Jul  12, 2016

@author: kurner

LAB:

Create the body of add_element, delete_element
using the input() function to drive a dialog with
the user
"""

from collections import namedtuple
import json

Element = namedtuple("Atom", "protons abbrev long_name mass")

def load_elements():
    global all_elements  # <--- will be visible to entire module
    f = open("elements.json", "r")
    the_dict = json.load(f)
    f.close()
    all_elements = {}
    for symbol, data in the_dict.items():
        all_elements[symbol] = Element(*data) # "explode" data into 4 inputs

Here's my outline from last night:

# -*- coding: utf-8 -*-
"""
Created on Tue Jul  12, 2016

Course: PYT-PR (Saisoft.net)
Session 03

Instructor:
Kirby Urner
kirby.urner at gmail.com

Audio Check (6:15 PM PDT)

Introduction
   What's an API
   The "API Economy"

Types we've seen: int float string
tuple dict list datetime date time timedelta
range slice namedtuple

Intro to Functions (one type of callable)
Intro to File I/O
Builtin Data types and JSON
Using input()
Using "in" to test for membership

Lab 1: enhance elements.py with an input() driven API

RESTful APIs and HTTP (URLs)
Sorting a List (sorted versus sort; reversed vs reverse)

Lab 2: install requests 3rd party module 'requests' with
conda, explore a movie database API

List Comprehension syntax

More on functions (how to call them)

Lab 3: create a function to nicely format
movie info returned by JSON

Summary of Session 03
"""

I'm also engaged in a parallel effort to educate adults
in my region who self organize a volunteer driving
religious non-profit (we don't say "church" or "temple"
but yeah, like a network of those things):

http://worldgame.blogspot.com/2016/07/npym-rest.html

Kirby


Kirby
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/edu-sig/attachments/20160713/4f06ea05/attachment.html>


More information about the Edu-sig mailing list