Nico Nico - 1 year ago 218
Python Question

How to check if a string in Python is in ASCII?

I want to I check whether a string is in ASCII or not.

I am aware of

, however when I try
, I have
TypeError: ord() expected a character, but string of length 2 found
. I understood it is caused by the way I built Python (as explained in
's documentation

Is there another way to check?

Answer Source
def is_ascii(s):
    return all(ord(c) < 128 for c in s)
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download