简体   繁体   中英

How to check Unicode char in python

def order_check_uni(body):  
    ccnt=0  
    for x in body:    
        if x.isUpper():  
            ccnt+=1  
        if ccnt>2:  
            print 'success'   
for x in body:
    if ord(x) > 127:
        # character is *not* ASCII

Not Sure, whats your exact requirement is

>>> u'aあä'.encode('ascii', 'ignore')
'a'

I Found this at Python: Convert Unicode to ASCII without errors

you can chech if a string is unicode by using the method isinstance()

s = u'aあä'
if isinstance(s, unicode):
  do_something()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM