Last active
July 4, 2017 02:58
-
-
Save insanity54/f78d44ae64e46b02e57e6ac061d91231 to your computer and use it in GitHub Desktop.
ascii-truncator.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
, ,_ | |
|`\ `;;, ,;;' | |
| `\ \ '. .'.' | |
| `\ \ '-""""-' / | |
`. `\ / |` | |
`> /; _ _ \ | |
/ / | . ; | |
< (`";\ () ~~~ (/_ | |
';;\ `, __ _.-'` ) | |
>;\ ` _.' | |
`;;\ \-' | |
;/ \ _ | |
| ,"". .` \ | |
| _| ' / | |
; /") .;-, | |
\ / __ .-' | |
\,_/-"` `-' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
, ,_ | |
|`\ `;;, ,;;' | |
| `\ \ '. .'.' | |
| `\ \ '-""""-' / | |
`. `\ / |` | |
`> /; _ _ \ | |
/ / | . ; | |
< (`";\ () ~~~ (/_ | |
';;\ `, __ _.-'` ) | |
>;\ ` _.' | |
`;;\ \-' | |
;/ \ _ | |
| ,"". .` \ | |
| _| ' / | |
; /") .;-, | |
\ / __ .-' | |
\,_/-"` `-' | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import sys | |
def getMinLineIndent(line): | |
count = 0 | |
for col in line: | |
count += 1 | |
if col != ' ': | |
return count | |
def removeBlankLines(lines): | |
newLines = [] | |
for line in lines: | |
goodLine = False | |
for col in line.rstrip(): | |
if col != ' ': | |
# if all columns are spaces, this line will be ignored | |
goodLine = True | |
if goodLine: | |
newLines.append(line) | |
return newLines | |
def getMinIndent(lines): | |
indents = [] | |
for line in lines: | |
indents.append(getMinLineIndent(line)) | |
return min(indents)-1 | |
def process(f): | |
f = removeBlankLines(f) | |
wc = getMinIndent(f) | |
#print "whitespace count is {0}".format(wc) | |
for line in f: | |
print line.rstrip()[wc:] | |
if not sys.argv[1:]: | |
print "USAGE: ./truncate.py ./pika.txt" | |
exit(2) | |
ifile = open(sys.argv[1], 'r') | |
process(ifile.readlines()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment