Mercurial > hg > TextShaper
comparison split.py @ 14:30f1781024a4
add splitline functionality
author | Jeff Hammel <k0scist@gmail.com> |
---|---|
date | Tue, 04 Feb 2014 14:44:47 -0800 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
13:c3df7dccb02b | 14:30f1781024a4 |
---|---|
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() |