Skip to content

Instantly share code, notes, and snippets.

@IT102Gists
Last active October 17, 2018 15:43
Show Gist options
  • Save IT102Gists/45f18a6348b38d1035e4f9bb68f31fa4 to your computer and use it in GitHub Desktop.
Save IT102Gists/45f18a6348b38d1035e4f9bb68f31fa4 to your computer and use it in GitHub Desktop.
Python CodeAlong: see how many people are in space *right now* with Python.
# Python's built-in module for encoding and decoding JSON data
import json
# Python's built-in module for opening and reading URLs
from urllib.request import urlopen
# this api returns the current number of people in space
url = "http://api.open-notify.org/astros.json"
# send a request and get a JSON response
resp = urlopen(url)
astro_data = json.load(resp)
# example of iterating through astro data
for astro in astro_data["people"]:
print(astro["name"])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment