Skip to content

Instantly share code, notes, and snippets.

@aso2101
Last active July 21, 2017 22:29
Show Gist options
  • Save aso2101/313fd72d237c92df1e22d6a5716829da to your computer and use it in GitHub Desktop.
Save aso2101/313fd72d237c92df1e22d6a5716829da to your computer and use it in GitHub Desktop.
Devanagari to Arabic numerals
import re
f = open('surasundari.xml','r')
w = open('surasundari-lg.xml','w')
num = re.compile(r'"([०१२३४५६७८९]+)"')
d2r_num = {'०':'0', '१':'1', '२':'2', '३':'3', '४':'4', '५':'5', '६':'6', '७':'7','८':'8','९':'9'}
text = f.readlines()
def num_d2r(number):
rString = ''
for s in str(number):
rString += d2r_num[s]
return str(rString)
for i in range(len(text)):
match = num.search(text[i])
if (match):
result = re.sub(match.group(1),num_d2r(match.group(1)),text[i])
else:
result = text[i]
w.write(result)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment