35 lines
677 B
Python
Executable File
35 lines
677 B
Python
Executable File
#!/usr/bin/env python3
|
|
"""Check file for non-ascii lines."""
|
|
|
|
from sys import argv
|
|
|
|
path = argv[1]
|
|
|
|
print('Path:', path)
|
|
|
|
|
|
def isascii(string):
|
|
try:
|
|
string_ascii = string.encode('ascii')
|
|
return True
|
|
except UnicodeEncodeError:
|
|
return False
|
|
|
|
|
|
def check_file():
|
|
num = 0
|
|
with open(path) as f:
|
|
for n, line in enumerate(f):
|
|
res = isascii(line)
|
|
if res:
|
|
continue
|
|
else:
|
|
print('Line {} is non-ascii:'.format(n + 1))
|
|
print(line.strip('\n'))
|
|
num += 1
|
|
continue
|
|
print('Found {} non-ascii lines'.format(num))
|
|
|
|
|
|
check_file()
|