[Tutor] getopt matching incorrect options

David Rock david at graniteweb.com
Tue Jul 12 05:37:54 CEST 2005


* Jay Loden <python at jayloden.com> [2005-07-11 22:30]:
> I have an app that takes a command line argument of -l or --list.  It uses the 
> getopt module to parse the arguments, and I just noticed that for some 
> reason, getopt is matching "--lis" or "--li" etc to "--list". (Code pasted in 
> below)
> 
> Is this normal behavior, and if so, is there any way to avoid this? I just 
> want it to match "--list" to "--list", not "--l" and "--li" and "--lis" etc. 

This is normal.

From getopt http://docs.python.org/lib/module-getopt.html

 Long options on the command line can be recognized so long as they
 provide a prefix of the option name that matches exactly one of the
 accepted options. For example, if long_options is ['foo', 'frob'], the
 option --fo will match as --foo, but --f will not match uniquely, so
 GetoptError will be raised.

-- 
David Rock
david at graniteweb.com
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
Url : http://mail.python.org/pipermail/tutor/attachments/20050711/844b0343/attachment-0001.pgp


More information about the Tutor mailing list