Skip to content

Instantly share code, notes, and snippets.

@igilham igilham/randline.py
Created Jan 5, 2011

Embed
What would you like to do?
Read a random line from a file
#!/usr/bin/env python
import os
import random
import sys
def randline(fname):
result = ''
if os.path.exists(fname):
result = random.choice([line for line in open(fname)])
return result
def main(*args):
for arg in args[1:]:
print(randline(arg))
return 0
if __name__ == "__main__":
sys.exit(main((*sys.argv))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.