I wrote a function in Python which is used to tell me whether the two words are similar or not.
Now I want to pass Japanese text in my same function. It is giving error "not a ascii character." I tried using utf-8 encoding, but then it giving the same error
Non-ASCII character '\xe3' in file
Is there any way to do that? I cant generate the msg file for that since the 2 keyword will be not be constant.
Here goes the code
def filterKeyword(keyword, adText, filterType):
if (filterType == 'contains'):
try :
adtext = str.lower(adText)
keyword = str.lower(keyword)
if (adtext.find(keyword)!=-1):
return '0'
except:
return '1'
if (filterType == 'exact'):
var = cmp(str.lower(adText), str.lower(keyword))
if(var == 0 ):
return '0'
return '1'
I have used the following:
filterKeyword(unicode('ポケモン').encode("utf-8"), unicode('黄色のポケモン').encode("utf-8"), 'contains')
filterKeyword('ポケモン'.encode("utf-8"), '黄色のポケモン'.encode("utf-8"), 'contains')
Both of them are giving the error.