daily pastebin goal
41%
SHARE
TWEET

Untitled

a guest Feb 20th, 2019 64 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. id_data = "whatever"
  2. data1 = {"body": { "type1": { "id": id_data, "col1": "col1_data", "col2": "col2_data"} }}
  3. data2 = { "body": { "id": id_data, "col2": "col2_data"}}
  4.  
  5. def printit(d):
  6.     # try to acces d["body"]["type1"] - fallback to d["body"] - store it
  7.     myd = d["body"].get("type1",d["body"])
  8.     did = myd.get("id")      # get id
  9.     col1 = myd.get("col1")   # mabye get col1
  10.     col2 = myd.get("col2")   # get col2
  11.  
  12.     # print what is surely there, check for those that might miss
  13.     print(did)
  14.     if col1:
  15.         print(col1)
  16.     print(col2 + "n")
  17.  
  18.  
  19. printit(data1)
  20. printit(data2)
  21.      
  22. # data1
  23. whatever
  24. col1_data
  25. col2_data
  26.  
  27. # data2
  28. whatever
  29. col2_data
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top