Advertisement
Guest User

Untitled

a guest
Mar 29th, 2015
234
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.91 KB | None | 0 0
  1. import json,sys, linecache
  2. from pprint import pprint
  3.  
  4. def jsonExtract(file):
  5.     with open(file) as data_file:    
  6.         data = json.load(data_file)
  7.     for i in data['projects']:
  8.         keyList = i.keys()
  9.         pprint(keyList)
  10.         #print keyList['category']
  11.         for j in i.keys():
  12.             if isinstance(i[str(j)],dict):
  13.                 print str(i[str(j)].keys())
  14. if __name__ == '__main__':
  15.     try:
  16.         print "pre exec"
  17.         jsonExtract('webContent.json')
  18.         print "executed"
  19.     except TypeError as e:
  20.         printException()
  21.         print "Something went wrong:...",e,"...on line",str(sys.exc_info()[2].tb_lineno)
  22. def printException():
  23.     exc_type, exc_obj, tb = sys.exc_info()
  24.     f = tb.tb_frame
  25.     lineno = tb.tb_lineno
  26.     filename = str(f.f_code)
  27.     linecache.checkcache(filename)
  28.     line = linecache.getline(filename, lineno, f.f_globals)
  29.     print 'EXCEPTION IN ({}, LINE {} "{}"): {}'.format(filename, lineno, line.strip(), exc_obj)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement