mon image

getopt

Yves Guidet (yves.guidet@gmail.com)

19/12/2017

getopt

An example using only Unix style options:

  
  >>> import getopt
  >>> args = '-a -b -cfoo -d bar a1 a2'.split()
  >>> args
  ['-a', '-b', '-cfoo', '-d', 'bar', 'a1', 'a2']
  >>> optlist, args = getopt.getopt(args, 'abc:d:')
  >>> optlist
  [('-a', ''), ('-b', ''), ('-c', 'foo'), ('-d', 'bar')]
  >>> args
  ['a1', 'a2']
  
  %	Using long option names is equally easy:



Retour à la page d'accueil

© Yves Guidet jeudi 9 juillet 2020, 09:48:17 (UTC+0200) (bella ubuntu, site printemps) yves.guidet@gmail.com