Guest User

Untitled

a guest
May 16th, 2018
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.44 KB | None | 0 0
  1. import re
  2.  
  3. filePath = '/Users/u/filewithspecialcharacters.csv'
  4. fileEncoding = 'iso-8859-1'
  5.  
  6. pattern = r"^[a-zA-Z0-9_;:!@?'.#(){}*|~/+%&<>,–`=\"\s\-\$\[\]\^\\]*$"
  7. compiledPattern = re.compile(pattern)
  8.  
  9. count = 0
  10.  
  11. with open(filePath,'r',encoding=fileEncoding) as file:
  12. for line in file:
  13. if not re.match(compiledPattern, line):
  14. count = count + 1
  15. print(line)
  16.  
  17. print('No of lines with special characters: ',count)
Add Comment
Please, Sign In to add comment