def getopt(args, shortopts, longopts=[]):
 opts = []
 if (type(longopts) == type('')):
  longopts = [longopts]
 else:
  longopts = list(longopts)
 while (args and args[0].startswith('-') and (args[0] != '-')):
  if (args[0] == '--'):
   args = args[1:]
   break
  if args[0].startswith('--'):
   (opts, args) = do_longs(opts, args[0][2:], longopts, args[1:])
  else:
   (opts, args) = do_shorts(opts, args[0][1:], shortopts, args[1:])
 return (opts, args)

def getopt ( args , shortopts , longopts = [ ] ) : opts = [ ] if ( type ( longopts ) == type ( '' ) ) : longopts = [ longopts ] else : longopts = list ( longopts ) while ( args and args [ 0 ] . startswith ( '-' ) and ( args [ 0 ] != '-' ) ) : if ( args [ 0 ] == '--' ) : args = args [ 1 : ] break if args [ 0 ] . startswith ( '--' ) : ( opts , args ) = do_longs ( opts , args [ 0 ] [ 2 : ] , longopts , args [ 1 : ] ) else : ( opts , args ) = do_shorts ( opts , args [ 0 ] [ 1 : ] , shortopts , args [ 1 : ] ) return ( opts , args )
getopt -> opts .