[Tutor] Command line arguments passing
dndfan at hotpop.com
Sun Dec 4 11:04:00 CET 2005
On Sat, 2005-12-03 at 17:23 -0800, Danny Yoo wrote:
> > > My question is: when invoking a program with, let's say, a filename
> > > containing spaces as a parameter:
> > >
> > > myprog -file "Long name"
> > >
> > > What does sys.argv hold in this case? I am specifically interested in
> > > whether argv=="\"Long" or argv=="Long name",
> Hi Vlad,
> What you're asking is a platform-specific thing. I believe it should do
> what you're expecting --- "Long name" should be a pulled together as a
> single argument in sys.argv. But it's not Python that's pulling "Long
> name" together: it's your operating system's command line shell that's
> doing this.
> For example, on Windows, the following pages:
> talk about how Windows does command line argument parsing. (Search those
> pages for the word "quote", and you'll see a mention of this.) And the
> details on the role of quoting arguments is simliar for Unix shells like
> 'bash' or 'tcsh'. For example, for the bash shell:
> So all Python knows is that it's getting an array of strings: it doesn't
> even see the original line that the user typed at the command line prompt;
> it instead gets something that has already been partially digested by your
> command line shell.
> Hope this helps!
Thanks, that's what I was looking for -- a multiplatform reference,
since I can't test scripts on Windows just yet.
More information about the Tutor