Skip to content

Instantly share code, notes, and snippets.

@a358003542
Last active November 24, 2019 00:48
Show Gist options
  • Save a358003542/6e6c0a654a9b2d4ae92d141161dbf767 to your computer and use it in GitHub Desktop.
Save a358003542/6e6c0a654a9b2d4ae92d141161dbf767 to your computer and use it in GitHub Desktop.
import click
import random
def random_choice(input):
line = random.choice(open(input, encoding='utf8').readlines())
if line:
return line
else:
return random_choice(input)
@click.command()
@click.argument('input', type=click.Path(exists=True))
def main(input):
line = random_choice(input)
click.echo(line)
click.pause()
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment