Detect string has non-ASCII chars without checking each char?

Michel Claveau - MVP enleverLesX_XXmcX at XmclavXeauX.com.invalid
Sun Aug 22 09:07:04 CEST 2010


Hi! 

Another way : 

  # -*- coding: utf-8 -*-

  import unicodedata

  def test_ascii(struni):
      strasc=unicodedata.normalize('NFD', struni).encode('ascii','replace')
      if len(struni)==len(strasc):
         return True
      else:
         return False

  print test_ascii(u"abcde")
  print test_ascii(u"abcdê")



@-salutations
-- 
Michel Claveau 



More information about the Python-list mailing list