Please tell why the below code is giving the error though both indicates the same option.
In [3]: parser = optparse.OptionParser()
In [4]: parser.add_option("--currencies", "--currency", "--ccy")
Out[4]: <Option at 0x7f113e6c4488: --currencies/--currency/--ccy>
In [5]: parser.parse_args(["--curr", "CHF"])
Usage: ipython [options]
ipython: error: ambiguous option: --curr (--currencies, --currency?)
An exception has occurred, use %tb to see the full traceback.
There is no real docs about this, but you can check the source code and see what happen.
In brief, optparse will check if given arguments are not too close from each other.
If two arguments (or more) starts by the same string (like foo, foobar and foofoo which all starts by foo) it will raise an AmbiguousOptionError.
In your case, --currencies and --currency starts by --curr, so when you ask to parse --curr optparse cannot say if you want to say --currency or --currencies.
If you use "argparse" instead of "optparse", then you can add "allow_abbrev=False" attribute to ignore this error.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With