
from pprint import pprint
import json
import sys

if __name__ == '__main__':
    if len(sys.argv) >= 2:
        path = sys.argv[1].split('.')
    else:
        path = ['error', 'stack']

    obj = json.load(sys.stdin)

    try:
        for part in path:
            obj = obj[part]
    except KeyError:
        pass

    if isinstance(obj, str):
        print(obj)
    else:
        pprint(obj)


from pprint import pprint
import json
import sys

def get(obj, path):
    try:
        for part in path:
            obj = obj[part]
        return obj
    except KeyError:
        return None

if __name__ == '__main__':
    if len(sys.argv) >= 2:
        paths = [sys.argv[1].split('.')]
    else:
        paths = [
            ['meta', 'error', 'stack'],
            ['error', 'stack'],
            ['traceback'],
        ]

    obj = json.load(sys.stdin)

    for path in paths:
        subobj = get(obj, path)
        if subobj is not None:
            obj = subobj
            break

    if isinstance(obj, str):
        print(obj)
    else:
        pprint(obj)

Improve stacktrace print for traceback.
Improve stacktrace print for traceback.

  
  from pprint import pprint
  import json
  import sys
  
+ def get(obj, path):
+     try:
+         for part in path:
+             obj = obj[part]
+         return obj
+     except KeyError:
+         return None
+ 
  if __name__ == '__main__':
      if len(sys.argv) >= 2:
-         path = sys.argv[1].split('.')
+         paths = [sys.argv[1].split('.')]
      else:
+         paths = [
+             ['meta', 'error', 'stack'],
-         path = ['error', 'stack']
+             ['error', 'stack'],
+             ['traceback'],
+         ]
  
      obj = json.load(sys.stdin)
  
-     try:
-         for part in path:
+     for path in paths:
+         subobj = get(obj, path)
+         if subobj is not None:
-             obj = obj[part]
+             obj = subobj
+             break
-     except KeyError:
-         pass
  
      if isinstance(obj, str):
          print(obj)
      else:
          pprint(obj)
  
Improve stacktrace print for traceback.
## Code Before:

from pprint import pprint
import json
import sys

if __name__ == '__main__':
    if len(sys.argv) >= 2:
        path = sys.argv[1].split('.')
    else:
        path = ['error', 'stack']

    obj = json.load(sys.stdin)

    try:
        for part in path:
            obj = obj[part]
    except KeyError:
        pass

    if isinstance(obj, str):
        print(obj)
    else:
        pprint(obj)

## Instruction:
Improve stacktrace print for traceback.
## Code After:

from pprint import pprint
import json
import sys

def get(obj, path):
    try:
        for part in path:
            obj = obj[part]
        return obj
    except KeyError:
        return None

if __name__ == '__main__':
    if len(sys.argv) >= 2:
        paths = [sys.argv[1].split('.')]
    else:
        paths = [
            ['meta', 'error', 'stack'],
            ['error', 'stack'],
            ['traceback'],
        ]

    obj = json.load(sys.stdin)

    for path in paths:
        subobj = get(obj, path)
        if subobj is not None:
            obj = subobj
            break

    if isinstance(obj, str):
        print(obj)
    else:
        pprint(obj)
