Skip to content

배토의 개발일지

나를위한 단편적 기억들의 기록

Menu
  • 안드로이드
  • 코틀린
  • Godot
  • 블렌더
  • git
  • 게임제작일지
  • 기타
Menu

python 커맨드라인 프로그램 만들기 : argparse

Posted on 2020년 3월 6일2020년 4월 16일 by batmask

python에서 커맨드라인 프로그램은 argparse를 import해서 쉽게 만들 수 있다.

import argparse

import os
import sys

my_parser = argparse.ArgumentParser(description="List the content of a folder",
                                    epilog="Enjoy the program! :)",
                                    prefix_chars='/')

my_parser.add_argument("Path",
                       metavar="path",
                       type=str,
                       help="the path to list")

args = my_parser.parse_args()

input_path = args.Path

if not os.path.isdir(input_path):
    print("The path specified does not exist")
    sys.exit()

print('\n'.join(os.listdir(input_path)))

답글 남기기 응답 취소

이메일 주소는 공개되지 않습니다. 필수 필드는 *로 표시됩니다

최신 글

  • Blender : snap을 써서 다른 vertex에 정렬하기
  • KTor Client 기본 사용 정리
  • 게임 만들거다.
  • Using Koin with Android Compose

보관함

2020 3월
일 월 화 수 목 금 토
1234567
891011121314
15161718192021
22232425262728
293031  
« 8월   4월 »

메타

  • 로그인
  • 엔트리 피드
  • 댓글 피드
  • WordPress.org
©2025 배토의 개발일지 | Built using WordPress and Responsive Blogily theme by Superb