redefined asino

This commit is contained in:
Your Name 2016-06-02 22:30:37 -04:00
parent 5d690a73c1
commit 673b3d1c52

View file

@ -1,14 +1,48 @@
import random, sys #!/usr/bin/python3
import random
if __name__ == '__main__': def parse_args ():
args = list() import argparse
if not sys.stdin.isatty(): parser = argparse.ArgumentParser ()
for line in sys.stdin: parser.add_argument ('-n', '--no-numbers', action = 'store_true', default = False,
help = 'do not display line numbers')
parser.add_argument ('choices', type = str, nargs= '*', default = [],
help = 'where the various choices belong')
parser.add_argument ('-l', '--limit', type = int, default = False,
help = 'display n lines')
return parser.parse_args ()
_cnt = -1
def enum ():
global _cnt
_cnt += 1
return (''.join ([str (_cnt), '. ']))
def null_string ():
return ''
def main ():
from sys import stdin
args = parse_args ()
if args.limit:
limit = args.limit - 2
if args.no_numbers:
fst = null_string
else:
fst = enum
if not stdin.isatty():
for line in stdin:
if line[-1] is '\n': if line[-1] is '\n':
line = line[:-1] line = line[:-1]
args.append(line) args.choices.append(line)
else:
args = sys.argv[1:] argRange = len(args.choices)
argRange = len(args) for i in range (argRange):
for i in range(argRange): print (''.join ([fst (), args.choices.pop(random.randrange(0, len(args.choices)))]))
print(str(i+1) + '.', args.pop(random.randrange(0, len(args)))) if args.limit and i > limit:
exit ()
if __name__ == '__main__':
main ()