Last active
October 17, 2018 15:43
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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