i write this function for check if month in persian exist in uicode string, replace it with number of month . i use this encode in header
`#!/usr/bin/python
# -*- coding: utf-8 -*-`
this is my def to convert month
def changeData(date):
if date:
date.encode('utf-8')
if "فروردین".encode('utf-8') in date:
return str.replace(":فروردین", ":1")
elif "اردیبهشت".encode('utf-8') in date:
return str.replace(":اردیبهشت", ":2")
elif "خرداد".encode('utf-8') in date:
return str.replace(":خرداد", ":3")
elif "تیر".encode('utf-8') in date:
return str.replace(":تیر", ":41")
elif "مرداد".encode('utf-8') in date:
return str.replace(":مرداد", ":5")
elif "شهریور".encode('utf-8') in date:
return str.replace(":شهریور", ":6")
elif "مهر".encode('utf-8') in date:
return str.replace(":مهر", ":7")
elif "آبان".encode('utf-8') in date:
return str.replace(":آبان", ":8")
elif "آذر".encode('utf-8') in date:
return str.replace(":آذر", ":9")
elif "دی".encode('utf-8') in date:
return str.replace(":دی", ":10")
elif "بهمن".encode('utf-8') in date:
return str.replace(":بهمن", ":11")
elif "اسفند".encode('utf-8') in date:
return str.replace(":اسفند", ":12")
i pass date with unicode format in function then convert it to encode('utf-8')
but give me this error
if "فروردین".encode('utf-8') in date:
UnicodeDecodeError: 'ascii' codec can't decode byte 0xd9 in position 0: ordinal not in range(128)
how i can solve this problem