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.ur...@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
_______________________________________________ Edu-sig mailing list Edu-sig@python.org https://mail.python.org/mailman/listinfo/edu-sig