Check the indent: 114: output += "\n" Specify the encoding when the json file is loaded: 46: with open(os.path.join(script_dir, "ipa_xsampa_map.json")) as f: --> with open(os.path.join(script_dir, "ipa_xsampa_map.json"), encoding="utf-8") as f: Because unicode is supported in Python 3.6, 86: line = unicode(line, 'utf-8').strip() --> line = line.strip() 117:sys.stdout.write(output.encode("utf-8")) --> sys.stdout.write(output) Change std input into arguments. 12: if len(sys.argv) != 4: