Random832於 2020年1月2日星期四 UTC+8上午5時04分36秒寫道:
> On Fri, Dec 27, 2019, at 23:08, jf...@ms4.hinet.net wrote:
> > > > optional arguments:
> > > >   -h, --help   show this help message and exit
> > > >   --foo [FOO]  foo help
> > > >   --goo GOO    goo help
> > > >
> > > > D:\Works\Python>py test.py --foo 1 --goo 2
> > > > 1 ['2']
> >
> > So the square bracket means optional, not list? My misunderstanding:-(
> 
> To be clear, the brackets in the print output do mean a list, and it is 
> because nargs=1 produces a list rather than the default (no nargs) which is 
> to produce a single value. This is not normally visible to the end user (it's 
> just a difference in how your program consumes the one mandatory argument), 
> so it's not reflected in the help output. Square brackets in the help output 
> mean an optional argument.

Yes, I have noticed my misunderstanding. I thought [FOO] in "--foo [FOO]" is a 
list until Chris had reminded me:-) Thank you for clarifying it in detail.

--Jach
-- 
https://mail.python.org/mailman/listinfo/python-list

Reply via email to