> For the complete documentation index, see [llms.txt](https://haleyryu.gitbook.io/engineer/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://haleyryu.gitbook.io/engineer/python/command-line.md).

# Command Line 활용하기

Python3 에서 sys.argv 를 사용하여 Command별 분기처리하기

##

## sys.argv 사용하기

## Command 분기하기&#x20;

```python
if __name__ == "__main__":
    command_executors = {
        'validate': command_validate,
        'test': command_test,
        'help': command_help
    }
    command = command_executors.get(sys.argv[1])
    
    try:
        command()
        sys.exit(0)
    except Exception as e:
        logger.error('error=%s\nTraceback:%s' % (str(e), traceback.format_exc()))
        sys.exit(1)
```
