command line utility for cups

George Fischhof george at fischhof.hu
Wed Jun 20 06:36:29 EDT 2018


Peter Otten <__peter__ at web.de> ezt írta (időpont: 2018. jún. 20., Sze
12:22):

> Brian Oney via Python-list wrote:
>
> > Dear all,
> >
> > I am having trouble with argparse. I am trying to translate the following
> > line to a sleek python script:
> >
> > lpr -o media=legal -o sides=two-sided-long-edge filename
> >
> > Now where I am.
> >
> > import argparse
> > parser = argparse.ArgumentParser(description='Print stuff with cups')
> > parser.add_argument('--printer', '-p',
> > help='Use this printer, try running: lpstat -a')
> > parser.add_argument('--options', '-o',
> > help='Options for this printer, try running: \
> > lpoptions -p PRINTER -l')
> >
> > parser.parse_known_args(['-o', 'sides=one-sided', '-o', 'test=crap'])
> > Namespace(options='test=crap', printer=None))
> >
> > How should I deal with multiple options being fed into my script?
> >
> > Thanks!
>
> Try action="append". You may also provide a type=split_func argument to
> split the key=value pairs:
>
> >>> import argparse
> >>> parser = argparse.ArgumentParser()
> >>> parser.add_argument("-o", action="append", type=lambda p: p.split("=",
> 1))
> _AppendAction(option_strings=['-o'], dest='o', nargs=None, const=None,
> default=None, type=<function <lambda> at 0x7feef70a8510>, choices=None,
> help=None, metavar=None)
> >>> parser.parse_args(["-o", "a=b", "-o", "c=d"])
> Namespace(o=[['a', 'b'], ['c', 'd']])
>
>
> --
> https://mail.python.org/mailman/listinfo/python-list



Hi,
You can also try click library from pypi, that is a very good command line
stuff.

George

>
>



More information about the Python-list mailing list