
import json, sys

if len(sys.argv) > 1:
    inFn = sys.argv[1]

with open(inFn, 'r') as f:
    try:
        defs = json.load(f)
    except:
        sys.exit('{} has a syntax error'.format(inFn))

sort = sorted(defs, key=str.lower)

print('# My Dictionary')
print('\n## Definitions')
curLetter = None
for k in sort:
    l = k[0].upper()
    if curLetter != l:
        curLetter = l
        print('\n### {}'.format(curLetter))
    word = k[0].upper() + k[1:]
    print('* *{}* - {}'.format(word, defs[k]))


import json, sys

if len(sys.argv) > 1:
    inFn = sys.argv[1]

with open(inFn, 'r') as f:
    try:
        defs = json.load(f)
    except ValueError as e:
        sys.exit('ValueError in {}: {}'.format(inFn, e))

sort = sorted(defs, key=str.lower)

print('# My Dictionary')
print('\n## Definitions')
curLetter = None
for k in sort:
    l = k[0].upper()
    if curLetter != l:
        curLetter = l
        print('\n### {}'.format(curLetter))
    word = k[0].upper() + k[1:]
    print('* *{}* - {}'.format(word, defs[k]))

Print more explicit error reports for input file parsing
Print more explicit error reports for input file parsing

  
  import json, sys
  
  if len(sys.argv) > 1:
      inFn = sys.argv[1]
  
  with open(inFn, 'r') as f:
      try:
          defs = json.load(f)
-     except:
-         sys.exit('{} has a syntax error'.format(inFn))
+     except ValueError as e:
+         sys.exit('ValueError in {}: {}'.format(inFn, e))
  
  sort = sorted(defs, key=str.lower)
  
  print('# My Dictionary')
  print('\n## Definitions')
  curLetter = None
  for k in sort:
      l = k[0].upper()
      if curLetter != l:
          curLetter = l
          print('\n### {}'.format(curLetter))
      word = k[0].upper() + k[1:]
      print('* *{}* - {}'.format(word, defs[k]))
  
Print more explicit error reports for input file parsing
## Code Before:

import json, sys

if len(sys.argv) > 1:
    inFn = sys.argv[1]

with open(inFn, 'r') as f:
    try:
        defs = json.load(f)
    except:
        sys.exit('{} has a syntax error'.format(inFn))

sort = sorted(defs, key=str.lower)

print('# My Dictionary')
print('\n## Definitions')
curLetter = None
for k in sort:
    l = k[0].upper()
    if curLetter != l:
        curLetter = l
        print('\n### {}'.format(curLetter))
    word = k[0].upper() + k[1:]
    print('* *{}* - {}'.format(word, defs[k]))

## Instruction:
Print more explicit error reports for input file parsing
## Code After:

import json, sys

if len(sys.argv) > 1:
    inFn = sys.argv[1]

with open(inFn, 'r') as f:
    try:
        defs = json.load(f)
    except ValueError as e:
        sys.exit('ValueError in {}: {}'.format(inFn, e))

sort = sorted(defs, key=str.lower)

print('# My Dictionary')
print('\n## Definitions')
curLetter = None
for k in sort:
    l = k[0].upper()
    if curLetter != l:
        curLetter = l
        print('\n### {}'.format(curLetter))
    word = k[0].upper() + k[1:]
    print('* *{}* - {}'.format(word, defs[k]))
