Skip to content

Instantly share code, notes, and snippets.

@RaD
Created June 4, 2015 08:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RaD/e4c0c1ecb94b7571dd4d to your computer and use it in GitHub Desktop.
Save RaD/e4c0c1ecb94b7571dd4d to your computer and use it in GitHub Desktop.
Sends the file to STDOUT in a line by line manner.
import argparse
import time
import sys
def read_by_line(input, delay, is_recourse):
while True:
input.seek(0)
for line in input:
sys.stdout.write(line)
time.sleep(delay/1000.0)
if not is_recourse:
break
if __name__ == '__main__':
parser = argparse.ArgumentParser(description='Sends a given file to stdout in per line manner.')
parser.add_argument('-r', action='store_true', default=False, dest='is_recourse',
help='send the file lines again and again.')
parser.add_argument('-d', action='store', default=250, dest='delay', type=int,
help='delay in milliseconds, by default 250ms.')
parser.add_argument('input', type=file, help='source file')
args = parser.parse_args()
try:
read_by_line(args.input, args.delay, args.is_recourse)
except KeyboardInterrupt:
pass
sys.exit(0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment