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
|
|
20 if close_quote is None:
|
|
21 close_quote = quote
|
|
22 return ["{}{}{}".format(quote, line, close_quote) for line in lines]
|
|
23
|
|
24
|
14
|
25 def main(args=sys.argv[1:]):
|
26
|
26 """CLI"""
|
14
|
27
|
|
28 parser = argparse.ArgumentParser(description=__doc__)
|
|
29 parser.add_argument('input', nargs='?',
|
|
30 type=argparse.FileType('r'), default=sys.stdin,
|
|
31 help='input file, or read from stdin if ommitted')
|
|
32 options = parser.parse_args(args)
|
|
33
|
26
|
34 lines = quotelines(options.input)
|
14
|
35
|
|
36 print '\n'.join(lines)
|
|
37
|
|
38 if __name__ == '__main__':
|
|
39 main()
|