Skip to content

Instantly share code, notes, and snippets.

@sapamja
Created June 9, 2014 22:43
Show Gist options
  • Save sapamja/3f153488dcb52f67c1f3 to your computer and use it in GitHub Desktop.
Save sapamja/3f153488dcb52f67c1f3 to your computer and use it in GitHub Desktop.
print_dump
def pp(json_docs):
"""preety print for json docs"""
print json.dumps(json_docs, indent=4)
def get_md5(key):
"""return md5 hex for key"""
md5 = hashlib.md5()
md5.update(key)
return md5.hexdigest()
def print_table(lod, args):
"""
Input: list of dictionary or list of list.
Args: list of headers name which is the key in dictionary
if preetyTable is not install then the output will be json format.
"""
try:
from prettytable import PrettyTable
pt = PrettyTable(border=True, horizontal_char='-',
field_names=[x.title() for x in args])
[pt.align.__setitem__(x.title(), "l") for x in args]
if isinstance(lod[0], dict):
[pt.add_row([x[item] for item in args]) for x in lod]
else:
[pt.add_row([x[i] for i in range(len(lod[0]))]) for x in lod]
return pt
except Exception:
pp(lod)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment