Author david.caro
Recipients david.caro
Date 2011-01-22.15:02:47
SpamBayes Score 1.80945e-05
Marked as misclassified No
Message-id <1295708573.96.0.520368257819.issue10981@psf.upfronthosting.co.za>
In-reply-to
Content
It is not an issue, it will try to match all the optional parameters, and if only one matches, then it will use it:

2110                 elif option_string.startswith(option_prefix):
2111                     action = self._option_string_actions[option_string]
2112                     tup = action, option_string, explicit_arg
2113                     result.append(tup)

and

2057         # if exactly one action matched, this segmentation is good,
2058         # so return the parsed action
2059         elif len(option_tuples) == 1:
2060             option_tuple, = option_tuples
2061             return option_tuple


if you try to add more than one optional parameter that matches the substring, it will complain:

>>> import argparse
>>> parser = argparse.ArgumentParser()
>>> parser.add_argument('--superstring')
_StoreAction(option_strings=['--superstring'], dest='superstring', nargs=None, const=None, default=None, type=None, choices=None, help=None, metavar=None)
>>> parser.parse_args(['--super','value'])
Namespace(superstring='value')
>>> parser.add_argument('--superstring2')
_StoreAction(option_strings=['--superstring'], dest='superstring', nargs=None, const=None, default=None, type=None, choices=None, help=None, metavar=None)
>>> parser.parse_args(['--super','value'])
usage: [-h] [--superstring SUPERSTRING] [--superstring2 SUPERSTRING2]
: error: ambiguous option: --super could match --superstring, --superstring2
History
Date User Action Args
2011-01-22 15:02:54david.carosetrecipients: + david.caro
2011-01-22 15:02:53david.carosetmessageid: <1295708573.96.0.520368257819.issue10981@psf.upfronthosting.co.za>
2011-01-22 15:02:47david.carolinkissue10981 messages
2011-01-22 15:02:47david.carocreate