理解Python诗歌1
\n我遇到了一个奇怪的问题。\n一个小应用程序 - 字典,在命令行中工作:
\n$ lexi\nUsage: lexi word\n\n$ lexi zoo\n\xd0\xb7\xd0\xbe\xd0\xbe\xd0\xbf\xd0\xb0\xd1\x80\xd0\xba\n\n$ lexi qwerty\nThere\'s not word \'qwerty\' is in the lexicon\nRun Code Online (Sandbox Code Playgroud)\n项目结构:
\n.\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 poetry_test\n\xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 __init__.py\n\xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 data\n\xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 lexicon.json # dictionary file\n\xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 lexi.py\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 pyproject.toml\nRun Code Online (Sandbox Code Playgroud)\n词典.py:
\n#!/usr/bin/env python3\n \nimport sys\nimport json\n \nLEXICON_DB = "poetry_test/data/lexicon.json"\n \n \ndef main():\n args = sys.argv\n if len(args) != 2:\n print("Usage: lexi word")\n sys.exit(1)\n \n word = args[1]\n lexicon = json.load(open(LEXICON_DB))\n translation = lexicon.get(word)\n if translation:\n print(translation)\n else:\n print(f"There\'s not …Run Code Online (Sandbox Code Playgroud)