1

What I want is to convert accented characters into english and if there is some other language present then it should give blank.I have tried certain codes like below but its converting even the other langagues to english below or removing them.What should I do?

def check1(email):
try:
    email = unicode(email, 'utf-8')
except (TypeError, NameError): # unicode is a default on python 3 
    pass
email = unicodedata.normalize('NFD', email)
email = email.encode('ascii', 'ignore')
email = email.decode("utf-8")
return email.upper()

check1("as平仮平ÇÈÈ.a@yah.comÈ")
ASCEE.A@YAH.COME

def acc(a):
outputString = unidecode.unidecode(a)
return outputString.upper()

acc("as平仮平ÇÈÈ.a@yah.comÈ")
ASPING JIA PING CEE.A@YAH.COME

The output I am expecting for

acc("as平仮平ÇÈÈ.a@yah.comÈ")

is this ("AS平仮平CEE.A@YAH.COME") .

Cuckoo
  • 97
  • 9
  • 1
    Can you add what you are expecting to get on each example please. – JGNI Aug 24 '21 at 09:04
  • Where you've used `email.encode('ascii', 'ignore')`, could you use `'replace'` in place of `'ignore'`? You could then replace the resulting question marks with spaces... Reference: https://www.w3schools.com/python/ref_string_encode.asp – Simon MᶜKenzie Aug 24 '21 at 09:06
  • Hello.The output I am expecting for acc("as平仮平ÇÈÈ.a@yah.comÈ") is this ("AS平仮平CEE.A@YAH.COME") . – Cuckoo Aug 25 '21 at 07:56

0 Answers0