{"id":105,"date":"2022-04-28T14:45:34","date_gmt":"2022-04-28T06:45:34","guid":{"rendered":"http:\/\/usei.cn\/?p=105"},"modified":"2022-04-28T14:45:35","modified_gmt":"2022-04-28T06:45:35","slug":"python-argparse","status":"publish","type":"post","link":"https:\/\/usei.cn\/index.php\/2022\/04\/28\/python-argparse\/","title":{"rendered":"python &#8211; argparse"},"content":{"rendered":"\n<pre id=\"ZmkNd\" class=\"wp-block-preformatted\">import argparse\n\nif __name__ == \"__main__\":\n    parser = argparse.ArgumentParser(description='********  \u9879\u76ee\u63a5\u53e3 ()   ********')\n    parser.add_argument('-url', type=str, help='\u9875\u9762\u5730\u5740url')\n    parser.add_argument('-save_path', type=str, help='\u5b58\u50a8\u5730\u5740')\n\n    args = parser.parse_args()  # \u89e3\u6790\u6dfb\u52a0\u53c2\u6570\n    unparsed = vars(args)  # parse_args()\u65b9\u6cd5\u7684\u8fd4\u56de\u503c\u4e3anamespace\uff0c\u7528vars()\u5185\u5efa\u51fd\u6570\u5316\u4e3a\u5b57\u5178\n\n    # \u83b7\u5f97\u4f20\u5165\u7684\u53c2\u6570\n    print(unparsed)\n    print(unparsed[\"url\"])\n<\/pre>\n\n\n\n<p id=\"448367e10d81fadaa7d2b3e906f23dbb\">\u67e5\u8be2 help \u4fe1\u606f<\/p>\n\n\n\n<pre id=\"qMjv1\" class=\"wp-block-preformatted\">python m.py -h\n\nusage: m.py [-h] [-url URL] [-save_path SAVE_PATH]\n******** \u9879\u76ee\u63a5\u53e3 () ********\noptional arguments:\n  -h, --help            show this help message and exit\n  -url URL              \u9875\u9762\u5730\u5740url\n  -save_path SAVE_PATH  \u5b58\u50a8\u5730\u5740\n<\/pre>\n\n\n\n<p id=\"87427fcd4f940800d69c79900a7b99d9\">\u4f20\u5165\u53c2\u6570<\/p>\n\n\n\n<pre id=\"erQx7\" class=\"wp-block-preformatted\">python m.py -url ddd -save_path dadas\n\n{'url': 'ddd', 'save_path': 'dadas'}\nddd<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>import argparse if __name__ == &#8220;__main__&#8221;: parser = arg [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[11],"tags":[],"class_list":["post-105","post","type-post","status-publish","format-standard","hentry","category-python"],"_links":{"self":[{"href":"https:\/\/usei.cn\/index.php\/wp-json\/wp\/v2\/posts\/105","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/usei.cn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/usei.cn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/usei.cn\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/usei.cn\/index.php\/wp-json\/wp\/v2\/comments?post=105"}],"version-history":[{"count":1,"href":"https:\/\/usei.cn\/index.php\/wp-json\/wp\/v2\/posts\/105\/revisions"}],"predecessor-version":[{"id":106,"href":"https:\/\/usei.cn\/index.php\/wp-json\/wp\/v2\/posts\/105\/revisions\/106"}],"wp:attachment":[{"href":"https:\/\/usei.cn\/index.php\/wp-json\/wp\/v2\/media?parent=105"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/usei.cn\/index.php\/wp-json\/wp\/v2\/categories?post=105"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/usei.cn\/index.php\/wp-json\/wp\/v2\/tags?post=105"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}