pythonansi

How to check for ANSI character in Python


I'm trying to validate a set of strings to report out the usage of illegal ANSI characters. I've read that extended ASCII is NOT exactly similar to ANSI. I've been trying to search for a way to check if a character is an ANSI character, but so far I found none. Does anyone know how to do this in Python?


Solution

  • Try with ord(c) function:

    def detect_non_printable(s):
        for c in s: 
            n = ord(c)
            if n < 32 or n > 126: 
               return "NON-PRINTABLE DETECTED" 
        return "PRINTABLE CHARS ONLY"