{"id":162,"date":"2020-03-06T09:40:37","date_gmt":"2020-03-06T00:40:37","guid":{"rendered":"http:\/\/batmask.dothome.co.kr\/?p=162"},"modified":"2025-09-09T09:18:05","modified_gmt":"2025-09-09T00:18:05","slug":"python-%ec%bb%a4%eb%a7%a8%eb%93%9c%eb%9d%bc%ec%9d%b8-%ed%94%84%eb%a1%9c%ea%b7%b8%eb%9e%a8-%eb%a7%8c%eb%93%a4%ea%b8%b0-argparse","status":"publish","type":"post","link":"http:\/\/batmask.net\/index.php\/2020\/03\/06\/162\/","title":{"rendered":"python \ucee4\ub9e8\ub4dc\ub77c\uc778 \ud504\ub85c\uadf8\ub7a8 \ub9cc\ub4e4\uae30 : argparse"},"content":{"rendered":"\n<p>python\uc5d0\uc11c \ucee4\ub9e8\ub4dc\ub77c\uc778 \ud504\ub85c\uadf8\ub7a8\uc740 argparse\ub97c import\ud574\uc11c \uc27d\uac8c \ub9cc\ub4e4 \uc218 \uc788\ub2e4.<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers\" data-code-block-pro-font-family=\"Code-Pro-Roboto-Mono.ttf\" style=\"font-size:clamp(14px, .875rem, 21px);font-family:Code-Pro-Roboto-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#adbac7;--cbp-line-number-width:calc(2 * 0.6 * .875rem);line-height:clamp(20px, 1.25rem, 30px);--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#22272e\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" style=\"color:#adbac7;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><pre class=\"code-block-pro-copy-button-pre\" aria-hidden=\"true\"><textarea class=\"code-block-pro-copy-button-textarea\" tabindex=\"-1\" aria-hidden=\"true\" readonly>import argparse\n\nimport os\nimport sys\n\nmy_parser = argparse.ArgumentParser(description=\"List the content of a folder\",\n                                    epilog=\"Enjoy the program! :)\",\n                                    prefix_chars='\/')\n\nmy_parser.add_argument(\"Path\",\n                       metavar=\"path\",\n                       type=str,\n                       help=\"the path to list\")\n\nargs = my_parser.parse_args()\n\ninput_path = args.Path\n\nif not os.path.isdir(input_path):\n    print(\"The path specified does not exist\")\n    sys.exit()\n\nprint('\\n'.join(os.listdir(input_path)))\n<\/textarea><\/pre><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki github-dark-dimmed\" style=\"background-color: #22272e\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #F47067\">import<\/span><span style=\"color: #ADBAC7\"> argparse<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #F47067\">import<\/span><span style=\"color: #ADBAC7\"> os<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F47067\">import<\/span><span style=\"color: #ADBAC7\"> sys<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #ADBAC7\">my_parser <\/span><span style=\"color: #F47067\">=<\/span><span style=\"color: #ADBAC7\"> argparse.ArgumentParser(<\/span><span style=\"color: #F69D50\">description<\/span><span style=\"color: #F47067\">=<\/span><span style=\"color: #96D0FF\">&quot;List the content of a folder&quot;<\/span><span style=\"color: #ADBAC7\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #ADBAC7\">                                    <\/span><span style=\"color: #F69D50\">epilog<\/span><span style=\"color: #F47067\">=<\/span><span style=\"color: #96D0FF\">&quot;Enjoy the program! :)&quot;<\/span><span style=\"color: #ADBAC7\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #ADBAC7\">                                    <\/span><span style=\"color: #F69D50\">prefix_chars<\/span><span style=\"color: #F47067\">=<\/span><span style=\"color: #96D0FF\">&#39;\/&#39;<\/span><span style=\"color: #ADBAC7\">)<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #ADBAC7\">my_parser.add_argument(<\/span><span style=\"color: #96D0FF\">&quot;Path&quot;<\/span><span style=\"color: #ADBAC7\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #ADBAC7\">                       <\/span><span style=\"color: #F69D50\">metavar<\/span><span style=\"color: #F47067\">=<\/span><span style=\"color: #96D0FF\">&quot;path&quot;<\/span><span style=\"color: #ADBAC7\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #ADBAC7\">                       <\/span><span style=\"color: #F69D50\">type<\/span><span style=\"color: #F47067\">=<\/span><span style=\"color: #6CB6FF\">str<\/span><span style=\"color: #ADBAC7\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #ADBAC7\">                       <\/span><span style=\"color: #F69D50\">help<\/span><span style=\"color: #F47067\">=<\/span><span style=\"color: #96D0FF\">&quot;the path to list&quot;<\/span><span style=\"color: #ADBAC7\">)<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #ADBAC7\">args <\/span><span style=\"color: #F47067\">=<\/span><span style=\"color: #ADBAC7\"> my_parser.parse_args()<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #ADBAC7\">input_path <\/span><span style=\"color: #F47067\">=<\/span><span style=\"color: #ADBAC7\"> args.Path<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #F47067\">if<\/span><span style=\"color: #ADBAC7\"> <\/span><span style=\"color: #F47067\">not<\/span><span style=\"color: #ADBAC7\"> os.path.isdir(input_path):<\/span><\/span>\n<span class=\"line\"><span style=\"color: #ADBAC7\">    <\/span><span style=\"color: #6CB6FF\">print<\/span><span style=\"color: #ADBAC7\">(<\/span><span style=\"color: #96D0FF\">&quot;The path specified does not exist&quot;<\/span><span style=\"color: #ADBAC7\">)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #ADBAC7\">    sys.exit()<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #6CB6FF\">print<\/span><span style=\"color: #ADBAC7\">(<\/span><span style=\"color: #96D0FF\">&#39;<\/span><span style=\"color: #F47067\">\\n<\/span><span style=\"color: #96D0FF\">&#39;<\/span><span style=\"color: #ADBAC7\">.join(os.listdir(input_path)))<\/span><\/span>\n<span class=\"line\"><\/span><\/code><\/pre><\/div>\n","protected":false},"excerpt":{"rendered":"<p>python\uc5d0\uc11c \ucee4\ub9e8\ub4dc\ub77c\uc778 \ud504\ub85c\uadf8\ub7a8\uc740 argparse\ub97c import\ud574\uc11c \uc27d\uac8c \ub9cc\ub4e4 \uc218 \uc788\ub2e4.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[33],"tags":[36,37,35,149,150,55],"class_list":["post-162","post","type-post","status-publish","format-standard","hentry","category-python","tag-argparse","tag-command-line","tag-python","tag-commandline-kr","tag-console-kr","tag-python-kr"],"jetpack_featured_media_url":"","_links":{"self":[{"href":"http:\/\/batmask.net\/index.php\/wp-json\/wp\/v2\/posts\/162","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/batmask.net\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/batmask.net\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/batmask.net\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/batmask.net\/index.php\/wp-json\/wp\/v2\/comments?post=162"}],"version-history":[{"count":10,"href":"http:\/\/batmask.net\/index.php\/wp-json\/wp\/v2\/posts\/162\/revisions"}],"predecessor-version":[{"id":3423,"href":"http:\/\/batmask.net\/index.php\/wp-json\/wp\/v2\/posts\/162\/revisions\/3423"}],"wp:attachment":[{"href":"http:\/\/batmask.net\/index.php\/wp-json\/wp\/v2\/media?parent=162"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/batmask.net\/index.php\/wp-json\/wp\/v2\/categories?post=162"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/batmask.net\/index.php\/wp-json\/wp\/v2\/tags?post=162"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}