Should I also parse mandatory arguments with getopt(...)
<pre><code>"""
Saves a dir listing in a file
Usage: python listfiles.py -d dir -f filename [flags]
Arguments:
  -d, --dir               dir; ls of which will be saved in a file
  -f, --file              filename (if existing will be overwritten)
Flags:
  -h, --help              show this help 
  -v, --verbose           be verbose
"""         

...

def usage():
  print __doc__

def main(args):
  verbose = False
  srcdir = filename = None
  try:
    opts, args = getopt.getopt(args,
                               'hvd:f:', ['help', 'verbose', 'dir=', 'file='])
  except getopt.GetoptError:
    usage()
    sys.exit(2)
  for opt, arg in opts:
    if opt in ('-h', '--help'):
      usage()
      sys.exit(0)
    if opt in ('-v', '--verbose'):
      verbose = True
    elif opt in ('-d', '--dir'):
      srcdir = arg
    elif opt in ('-f', '--file'):
      filename = arg
  if srcdir and filename:
    fsock = open(filename, 'w')
    write_dirlist_tosock(srcdir, fsock, verbose)
    fsock.close()
  else:
    usage()
    sys.exit(1)

if __name__ == '__main__':
  main(sys.argv[1:])  
</code></pre>

<p>I am not sure if it is pythonic to use <code>getopt()</code> to also handle mandatory arguments. Would appreciate some suggestions  </p>
