Skip to content

Instantly share code, notes, and snippets.

@packetchef
Created July 11, 2015 16:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save packetchef/faf409c4befb4270a5c2 to your computer and use it in GitHub Desktop.
Save packetchef/faf409c4befb4270a5c2 to your computer and use it in GitHub Desktop.
Pythonic printing of a dictionary and its contents
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