Mercurial > hg > TextShaper
comparison textshaper/split.py @ 16:4e00a2ce0a06
move
| author | Jeff Hammel <k0scist@gmail.com> |
|---|---|
| date | Sat, 22 Feb 2014 16:56:41 -0800 |
| parents | split.py@30f1781024a4 |
| children |
comparison
equal
deleted
inserted
replaced
| 15:497b29bba41b | 16:4e00a2ce0a06 |
|---|---|
| 1 #!/usr/bin/env python | |
| 2 # -*- coding: utf-8 -*- | |
| 3 | |
| 4 """ | |
| 5 split some lines | |
| 6 """ | |
| 7 | |
| 8 import argparse | |
| 9 import os | |
| 10 import sys | |
| 11 | |
| 12 def main(args=sys.argv[1:]): | |
| 13 | |
| 14 parser = argparse.ArgumentParser(description=__doc__) | |
| 15 parser.add_argument('input', nargs='?', | |
| 16 type=argparse.FileType('r'), default=sys.stdin, | |
| 17 help='input file, or read from stdin if ommitted') | |
| 18 parser.add_argument('--quote', dest='quote', | |
| 19 action='store_true', default=False) | |
| 20 options = parser.parse_args(args) | |
| 21 | |
| 22 read = options.input.read() | |
| 23 | |
| 24 lines = read.strip().split() | |
| 25 if options.quote: | |
| 26 lines = ["'{}'".format(line) for line in lines] | |
| 27 | |
| 28 print '\n'.join(lines) | |
| 29 | |
| 30 if __name__ == '__main__': | |
| 31 main() |
