Created
July 11, 2015 16:51
-
-
Save packetchef/faf409c4befb4270a5c2 to your computer and use it in GitHub Desktop.
Pythonic printing of a dictionary and its contents
This file contains 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
def prettyDictionary(**kwargs): | |
for name, value in kwargs.items(): | |
print('{name} :: {value}'.format(name=name, value=value)) | |
import urllib2 | |
import simplejson as json | |
url = 'http://ipinfo.io/json' | |
ipinfo = urllib2.urlopen(url).read() | |
jipinfo = json.loads(ipinfo) | |
# Show as a string | |
print(type(ipinfo)) | |
print ipinfo | |
# Show as a dictionary | |
print(type(jipinfo)) | |
print jipinfo | |
# And make it pretty | |
prettyDictionary(**jipinfo) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment