import json
import sys
import toml

fh = open(sys.argv[1])
try:
    data = toml.load(fh)
except toml.TomlDecodeError, e:
    print e
    sys.exit(1)
print json.dumps(data, indent=4, sort_keys=True)

import json
import sys
import toml

if len(sys.argv) > 1:
    fh = open(sys.argv[1])
else:
    fh = sys.stdin

try:
    data = toml.load(fh)
except toml.TomlDecodeError as e:
    print(e)
    sys.exit(1)
print(json.dumps(data, indent=4, sort_keys=True))

Switch toml to json script to python 3
Switch toml to json script to python 3

  import json
  import sys
  import toml
  
+ if len(sys.argv) > 1:
- fh = open(sys.argv[1])
+     fh = open(sys.argv[1])
+ else:
+     fh = sys.stdin
+ 
  try:
      data = toml.load(fh)
- except toml.TomlDecodeError, e:
+ except toml.TomlDecodeError as e:
-     print e
+     print(e)
      sys.exit(1)
- print json.dumps(data, indent=4, sort_keys=True)
+ print(json.dumps(data, indent=4, sort_keys=True))
  
Switch toml to json script to python 3
## Code Before:
import json
import sys
import toml

fh = open(sys.argv[1])
try:
    data = toml.load(fh)
except toml.TomlDecodeError, e:
    print e
    sys.exit(1)
print json.dumps(data, indent=4, sort_keys=True)

## Instruction:
Switch toml to json script to python 3
## Code After:
import json
import sys
import toml

if len(sys.argv) > 1:
    fh = open(sys.argv[1])
else:
    fh = sys.stdin

try:
    data = toml.load(fh)
except toml.TomlDecodeError as e:
    print(e)
    sys.exit(1)
print(json.dumps(data, indent=4, sort_keys=True))
