Mercurial > hg > TextShaper
annotate textshaper/quote.py @ 57:a2bbe406f570 default tip
which is no longer maintained; roll our mediocre own
author | Jeff Hammel <k0scist@gmail.com> |
---|---|
date | Mon, 20 Feb 2017 10:40:34 -0800 |
parents | 4aba57a33376 |
children |
rev | line source |
---|---|
14 | 1 #!/usr/bin/env python |
2 # -*- coding: utf-8 -*- | |
3 | |
4 """ | |
26 | 5 quote some lines |
14 | 6 """ |
7 | |
8 import argparse | |
9 import os | |
10 import sys | |
11 | |
26 | 12 def quotelines(text, quote="'", close_quote=None): |
13 """ | |
14 individually quote each line of text | |
15 | |
16 quote -- quote character to use | |
17 close_quote -- closing quote character, if different from opening quote | |
18 """ | |
19 | |
27
4aba57a33376
add decorator for converting text to lines of text
Jeff Hammel <k0scist@gmail.com>
parents:
26
diff
changeset
|
20 close_quote = quote if close_quote is None else close_quote |
26 | 21 return ["{}{}{}".format(quote, line, close_quote) for line in lines] |
22 | |
23 | |
14 | 24 def main(args=sys.argv[1:]): |
26 | 25 """CLI""" |
14 | 26 |
27 parser = argparse.ArgumentParser(description=__doc__) | |
28 parser.add_argument('input', nargs='?', | |
29 type=argparse.FileType('r'), default=sys.stdin, | |
30 help='input file, or read from stdin if ommitted') | |
31 options = parser.parse_args(args) | |
32 | |
26 | 33 lines = quotelines(options.input) |
14 | 34 |
35 print '\n'.join(lines) | |
36 | |
37 if __name__ == '__main__': | |
38 main() |