Created
October 7, 2015 16:09
-
-
Save oseiskar/59dd6fc6723060197245 to your computer and use it in GitHub Desktop.
Finds and highlights non-ASCII characters in STDIN, line-by-line
This file contains 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/python | |
"Finds and highlights non-ASCII characters in STDIN (python 2)" | |
import sys | |
def is_ascii(str): | |
try: | |
str.encode('ascii') | |
return True | |
except: return False | |
line_num = 0 | |
for line in sys.stdin: | |
line_num += 1 | |
if is_ascii(line): continue | |
sys.stdout.write("\nline %d:\n" % line_num) | |
underline = '' | |
for char in line: | |
if is_ascii(char): | |
underline += ' ' | |
else: | |
char = '?' | |
underline += '^' | |
sys.stdout.write(char) | |
sys.stdout.write(underline + '\n') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment