My code:
def check_string(text):
valid = bool(text and (not text.isascii() or any(t.isalnum() for t in text)))
return text if valid else ""
While I process some text, I got the following error:
File "/data/text_normalizer.py", line 176, in check_string
valid = bool(text and (not text.isascii() or any(t.isalnum() for t in text)))
AttributeError: 'str' object has no attribute 'isascii'
isascii() is indeed a function of a str object, so why does it report this error?