annotate onelineit.py @ 40:e1832eeae084

from http://k0s.org/hg/config
author Jeff Hammel <k0scist@gmail.com>
date Fri, 22 Aug 2014 15:54:19 -0700
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
40
e1832eeae084 from http://k0s.org/hg/config
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
1 #!/usr/bin/env python
e1832eeae084 from http://k0s.org/hg/config
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
2
e1832eeae084 from http://k0s.org/hg/config
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
3 def onelineit(string):
e1832eeae084 from http://k0s.org/hg/config
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
4 string = string.split('\n')
e1832eeae084 from http://k0s.org/hg/config
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
5 string = [ i.strip() or '\n' for i in string ]
e1832eeae084 from http://k0s.org/hg/config
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
6 string = ' '.join(string)
e1832eeae084 from http://k0s.org/hg/config
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
7 string = string.split('\n')
e1832eeae084 from http://k0s.org/hg/config
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
8 string = [ i.strip() for i in string if i.strip() ]
e1832eeae084 from http://k0s.org/hg/config
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
9
e1832eeae084 from http://k0s.org/hg/config
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
10 return '\n\n'.join(string)
e1832eeae084 from http://k0s.org/hg/config
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
11
e1832eeae084 from http://k0s.org/hg/config
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
12 if __name__ == '__main__':
e1832eeae084 from http://k0s.org/hg/config
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
13 import sys
e1832eeae084 from http://k0s.org/hg/config
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
14 print onelineit(sys.stdin.read())