All pastes #743022 Raw Edit

Miscellany

public text v1 · immutable
·published 2007-10-20 00:38 UTC
rendered paste body
if __name__ == '__main__':
    opt = {}
    opt['n'] = 1

    try:
	opts, args = getopt.getopt (sys.argv[1:], 'n:')
	for option, value in opts:
	    v = int (value)
	    if v < 0:
		raise ValueError, 'negative count: %d' % v
	    opt[option[1]] = v
    except (getopt.error, ValueError), e:
	usage (e)

    if len (args) != 1:
	usage ('wrong number of operands')
    input_file = args[0]
    line_count = opt['n']

    try:
	generator = randline (input_file)
	for i in range (line_count):
	    sys.stdout.write (generator.chooseline ())
    except IOError, e:
	sys.stderr.write ('randline.py: %s\n' % e)
	sys.exit (1)