Python Optparse list

S.Lott’s answer has already been accepted, but here’s a code sample for the archives: def foo_callback(option, opt, value, parser): setattr(parser.values, option.dest, value.split(‘,’)) parser = OptionParser() parser.add_option(‘-f’, ‘–foo’, type=”string”, action=’callback’, callback=foo_callback)

Python argparse ignore unrecognised arguments

Replace args = parser.parse_args() with args, unknown = parser.parse_known_args() For example, import argparse parser = argparse.ArgumentParser() parser.add_argument(‘–foo’) args, unknown = parser.parse_known_args([‘–foo’, ‘BAR’, ‘spam’]) print(args) # Namespace(foo=’BAR’) print(unknown) # [‘spam’]

Why use argparse rather than optparse?

As of python 2.7, optparse is deprecated, and will hopefully go away in the future. argparse is better for all the reasons listed on its original page (https://code.google.com/archive/p/argparse/): handling positional arguments supporting sub-commands allowing alternative option prefixes like + and / handling zero-or-more and one-or-more style arguments producing more informative usage messages providing a much … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)