Mercurial > hg > TextShaper
diff textshaper/quote.py @ 26:c23782a7b7ba
more hookups, yo
author | Jeff Hammel <k0scist@gmail.com> |
---|---|
date | Sun, 23 Feb 2014 11:41:37 -0800 |
parents | a43d0ad17c29 |
children | 4aba57a33376 |
line wrap: on
line diff
--- a/textshaper/quote.py Sun Feb 23 10:59:10 2014 -0800 +++ b/textshaper/quote.py Sun Feb 23 11:41:37 2014 -0800 @@ -2,28 +2,36 @@ # -*- coding: utf-8 -*- """ -split some lines +quote some lines """ import argparse import os import sys +def quotelines(text, quote="'", close_quote=None): + """ + individually quote each line of text + + quote -- quote character to use + close_quote -- closing quote character, if different from opening quote + """ + + if close_quote is None: + close_quote = quote + return ["{}{}{}".format(quote, line, close_quote) for line in lines] + + def main(args=sys.argv[1:]): + """CLI""" parser = argparse.ArgumentParser(description=__doc__) parser.add_argument('input', nargs='?', type=argparse.FileType('r'), default=sys.stdin, help='input file, or read from stdin if ommitted') - parser.add_argument('--quote', dest='quote', - action='store_true', default=False) options = parser.parse_args(args) - read = options.input.read() - - lines = read.strip().split() - if options.quote: - lines = ["'{}'".format(line) for line in lines] + lines = quotelines(options.input) print '\n'.join(lines)