mirror of
https://github.com/FraMecca/Buridans_donkey.git
synced 2024-03-20 11:20:15 +01:00
redefined asino
This commit is contained in:
parent
5d690a73c1
commit
673b3d1c52
1 changed files with 45 additions and 11 deletions
54
asino.py
54
asino.py
|
@ -1,14 +1,48 @@
|
|||
import random, sys
|
||||
#!/usr/bin/python3
|
||||
import random
|
||||
|
||||
if __name__ == '__main__':
|
||||
args = list()
|
||||
if not sys.stdin.isatty():
|
||||
for line in sys.stdin:
|
||||
def parse_args ():
|
||||
import argparse
|
||||
parser = argparse.ArgumentParser ()
|
||||
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':
|
||||
line = line[:-1]
|
||||
args.append(line)
|
||||
else:
|
||||
args = sys.argv[1:]
|
||||
argRange = len(args)
|
||||
args.choices.append(line)
|
||||
|
||||
argRange = len(args.choices)
|
||||
for i in range (argRange):
|
||||
print(str(i+1) + '.', args.pop(random.randrange(0, len(args))))
|
||||
print (''.join ([fst (), args.choices.pop(random.randrange(0, len(args.choices)))]))
|
||||
if args.limit and i > limit:
|
||||
exit ()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main ()
|
||||
|
|
Loading…
Reference in a new issue