[Tutor] Arguments from the command line

Hugo Arts hugo.yoshi at gmail.com
Mon Sep 6 18:08:27 CEST 2010


On Mon, Sep 6, 2010 at 5:48 PM, aug dawg <augdawg09 at gmail.com> wrote:
> I've seen Python programs that can be activated from the command line. For
> example:
> hg
>
> This displays a list of commands for the Mercurial revision control system.
> But another command is this:
> hg commit "This is a commit name"
> Mercurial is written in Python. I know that commit is a function that
> commits to a repo, but what command does the program use in order to get the
> commit name, like "This is a commit name" (This would make a commit with
> "This is a commit name" as the commit name)
>

sys.argv is a list of all arguments from the command line. However,
you'll rarely deal with it directly, there's various modules that deal
with handling arguments. I believe the current one is argparse:
http://docs.python.org/library/argparse.html#module-argparse

Hugo


More information about the Tutor mailing list