Skip to content

Instantly share code, notes, and snippets.

@hktechn0
Created November 10, 2009 16:58
Show Gist options
  • Save hktechn0/231034 to your computer and use it in GitHub Desktop.
Save hktechn0/231034 to your computer and use it in GitHub Desktop.
isascii() on Python
def isascii(c, printable = False):
if 0x00 <= ord(c) <= 0x7f:
if printable:
if 0x20 <= ord(c) <= 0x7e:
return True
else:
return False
else:
return True
else:
return False
@hughdbrown
Copy link

I think this would work as well:

def isascii(c, printable=False):
    return ((0x00 <= ord(c) <= 0x7f) and
            (not printable or (0x20 <= ord(c) <= 0x7e)))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment