{"id":6021,"date":"2020-08-10T11:47:02","date_gmt":"2020-08-10T02:47:02","guid":{"rendered":"http:\/\/blog.jansnap.com\/?p=6021"},"modified":"2021-12-15T01:46:00","modified_gmt":"2021-12-14T16:46:00","slug":"python%e3%81%aeargparse%e3%81%a7%e3%80%8crequired%20is%20an%20invalid%20argument%20for%20positionals%e3%80%8d%e3%81%8c%e5%87%ba%e3%81%9f%e3%82%89%e3%80%81required%e3%82%92%e6%b6%88%e3%81%9b%e3%81%b0%e","status":"publish","type":"post","link":"https:\/\/blog.jansnap.com\/?p=6021","title":{"rendered":"Python\u306eargparse\u3067\u300c&#8217;required&#8217; is an invalid argument for positionals\u300d\u304c\u51fa\u305f\u3089\u3001required\u3092\u6d88\u305b\u3070\u3044\u3044"},"content":{"rendered":"<p>\u30c9\u30ad\u30e5\u30e1\u30f3\u30c8\u304c\u5c11\u3057\u5206\u304b\u308a\u3065\u3089\u304b\u3063\u305f\u306e\u3067\u30e1\u30e2\u3002<\/p>\n\n<h2><span class=\"ez-toc-section\" id=\"%E8%B5%B7%E5%8B%95%E6%99%82%E3%81%AE%E5%BC%95%E6%95%B0%E3%82%92%E4%BE%BF%E5%88%A9%E3%81%AB%E6%89%B1%E3%81%88%E3%82%8Bargparse%E3%83%A2%E3%82%B8%E3%83%A5%E3%83%BC%E3%83%AB\"><\/span>\n\u8d77\u52d5\u6642\u306e\u5f15\u6570\u3092\u4fbf\u5229\u306b\u6271\u3048\u308bargparse\u30e2\u30b8\u30e5\u30fc\u30eb<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n<p>Python\u306b\u306f\u3001\u8d77\u52d5\u6642\u306e\u5f15\u6570\u3092\u4fbf\u5229\u306b\u6271\u3048\u308b<a href=\"https:\/\/docs.python.org\/ja\/3\/library\/argparse.html\" rel=\"nofollow noopener\" target=\"_blank\">argparse\u30e2\u30b8\u30e5\u30fc\u30eb<\/a>\u304c\u3042\u308a\u307e\u3059\u3002<\/p>\n\n<h3><span class=\"ez-toc-section\" id=\"%E4%BD%8D%E7%BD%AE%E5%BC%95%E6%95%B0%E3%81%A8%E3%82%AA%E3%83%97%E3%82%B7%E3%83%A7%E3%83%B3%E5%BC%95%E6%95%B0\"><\/span>\n\u4f4d\u7f6e\u5f15\u6570\u3068\u30aa\u30d7\u30b7\u30e7\u30f3\u5f15\u6570<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n<p>argparse\u3067\u6271\u3046\u5f15\u6570\u306b\u306f\u4ee5\u4e0b\u306e2\u7a2e\u985e\u304c\u3042\u308a\u307e\u3059\u3002<\/p>\n\n<ul>\n<li>\u4f4d\u7f6e\u5f15\u6570(infile1\u306a\u3069)<\/li>\n<li>\u30aa\u30d7\u30b7\u30e7\u30f3\u5f15\u6570(-f\u3084\u2013bar\u306a\u3069)(=\u30d5\u30e9\u30b0)\n(<a href=\"https:\/\/docs.python.org\/ja\/3\/library\/argparse.html#name-or-flags\" rel=\"nofollow noopener\" target=\"_blank\">\u516c\u5f0f\u30c9\u30ad\u30e5\u30e1\u30f3\u30c8\u306eargparse\u306e\u300cname \u307e\u305f\u306f flags\u300d<\/a>\u306b\u66f8\u304b\u308c\u3066\u3044\u307e\u3059)<\/li>\n<\/ul>\n\n<h3><span class=\"ez-toc-section\" id=\"add_argument%E3%83%A1%E3%82%BD%E3%83%83%E3%83%89\"><\/span>\nadd_argument()\u30e1\u30bd\u30c3\u30c9<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n<p>\u3069\u3093\u306a\u5f15\u6570\u3092\u6307\u5b9a\u3067\u304d\u308b\u304b\u3092<code>add_argument()<\/code>\u30e1\u30bd\u30c3\u30c9\u3067\u6307\u5b9a\u3067\u304d\u307e\u3059\u304c\u3001\u4f4d\u7f6e\u5f15\u6570\u304c\u5fc5\u9808\u3060\u304b\u3089\u3068<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"text\" class=\"language-text\">argument.add_argument(\n    'infile1',\n    required=True,\n    help='input file'\n)<\/code><\/pre>\n\n\n\n<p>\u306e\u3088\u3046\u306b\u66f8\u3044\u3066\u3057\u307e\u3046\u3068\u3001\u5b9f\u884c\u6642\u306b\u300c<code>'required' is an invalid argument for positionals<\/code>\u300d\u3068\u30a8\u30e9\u30fc\u306b\u306a\u308a\u5b9f\u884c\u3067\u304d\u307e\u305b\u3093\u3002<\/p>\n\n<h3><span class=\"ez-toc-section\" id=\"%E3%80%8Crequired%E3%80%8D%E3%81%AF%E3%82%AA%E3%83%97%E3%82%B7%E3%83%A7%E3%83%B3%E5%BC%95%E6%95%B0%E3%81%AE%E3%81%BF%E3%81%AB%E6%8C%87%E5%AE%9A%E3%81%A7%E3%81%8D%E3%82%8B\"><\/span>\n\u300crequired\u300d\u306f\u30aa\u30d7\u30b7\u30e7\u30f3\u5f15\u6570\u306e\u307f\u306b\u6307\u5b9a\u3067\u304d\u308b<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n<p>\u300c<code>required<\/code>\u300d\u306f\u30aa\u30d7\u30b7\u30e7\u30f3\u5f15\u6570\u306b\u5bfe\u3059\u308b\u6307\u5b9a\u306a\u305f\u3081\u3001\u4f4d\u7f6e\u5f15\u6570\u306b\u6307\u5b9a\u3059\u308b\u3068\u30a8\u30e9\u30fc\u306b\u306a\u308a\u307e\u3059\u3002<br>\n\u3082\u3068\u3082\u3068\u4f4d\u7f6e\u5f15\u6570\u306f\u5fc5\u9808\u306a\u305f\u3081\u3001\u8a72\u5f53\u30aa\u30d7\u30b7\u30e7\u30f3\u306e\u300crequired=True\u300d\u3092\u6d88\u305b\u3070\u3001\u60f3\u5b9a\u3057\u305f\u52d5\u4f5c\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u30c9\u30ad\u30e5\u30e1\u30f3\u30c8\u304c\u5c11\u3057\u5206\u304b\u308a\u3065\u3089\u304b\u3063\u305f\u306e\u3067\u30e1\u30e2\u3002<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4138,4070,4071,4140,4139],"tags":[4135,4065,4066,4137,4136],"class_list":["post-6021","post","type-post","status-publish","format-standard","hentry","category-argparse","category-python","category-python3","category-4140","category-4139","tag-argparse","tag-python","tag-python3","tag-4137","tag-4136"],"_links":{"self":[{"href":"https:\/\/blog.jansnap.com\/index.php?rest_route=\/wp\/v2\/posts\/6021","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.jansnap.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.jansnap.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.jansnap.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.jansnap.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=6021"}],"version-history":[{"count":0,"href":"https:\/\/blog.jansnap.com\/index.php?rest_route=\/wp\/v2\/posts\/6021\/revisions"}],"wp:attachment":[{"href":"https:\/\/blog.jansnap.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=6021"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.jansnap.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=6021"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.jansnap.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=6021"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}