Mercurial > hg > TextShaper
comparison textshaper/onelineit.py @ 42:1a80204bd562
basic cli
author | Jeff Hammel <k0scist@gmail.com> |
---|---|
date | Mon, 25 Aug 2014 19:31:16 -0700 |
parents | 56199789d2a0 |
children | 21b6a9569f21 |
comparison
equal
deleted
inserted
replaced
41:56199789d2a0 | 42:1a80204bd562 |
---|---|
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 | 2 |
3 """ | |
4 make a string one line | |
5 """ | |
6 | |
7 import sys | |
8 | |
3 def onelineit(string): | 9 def onelineit(string): |
10 """make a string one line""" | |
11 | |
4 string = string.split('\n') | 12 string = string.split('\n') |
5 string = [ i.strip() or '\n' for i in string ] | 13 string = [ i.strip() or '\n' for i in string ] |
6 string = ' '.join(string) | 14 string = ' '.join(string) |
7 string = string.split('\n') | 15 string = string.split('\n') |
8 string = [ i.strip() for i in string if i.strip() ] | 16 string = [ i.strip() for i in string if i.strip() ] |
9 | 17 |
10 return '\n\n'.join(string) | 18 return '\n\n'.join(string) |
11 | 19 |
20 def main(args=sys.argv[1:]): | |
21 """CLI""" | |
22 print (onelineit(sys.stdin.read())) | |
23 | |
12 if __name__ == '__main__': | 24 if __name__ == '__main__': |
13 import sys | 25 main() |
14 print onelineit(sys.stdin.read()) |