Advertisement
user_137

Show Invalid Characters

Sep 8th, 2020 (edited)
1,621
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.66 KB | None | 0 0
  1. s = """Put your submission here between the triple quotes for testing.
  2. This is a sample multiline string with a backspace char \b to show how
  3. any errors you have will be displayed"""
  4.  
  5. # ord finds the numeric value of a character for testing
  6. valid_chars = [9,10,11,12,13] + list(range(32, 127))
  7. all_valid = True
  8. print()
  9. for i, c in enumerate(s):
  10.     if ord(c) not in valid_chars:
  11.         all_valid = False
  12.         print("Oops, character", c, "with ordinal value:", ord(c), "at position", i)
  13.         print("Its the middle char here: ", '"' + s[i-7: i] + '_' + s[i+1: i+8] + '"')
  14. print(f"\nAll characters were {'' if all_valid else 'NOT '}valid printable ASCII")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement