Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python
- # -*- coding: utf-8 -*-
- # recode a file from arabic windows(windows-1256) to utf8
- import sys, os
- def winArabicToUtf8(s, ar2fa=True):
- u = s.decode('windows-1256')
- if ar2fa:
- for item in [
- (u'ي',u'ی'),
- (u'ك',u'ک'),
- (u'ۀ',u'هٔ')]:
- u = u.replace(item[0], item[1])
- return u.encode('utf8')
- path = sys.argv[1]
- s = file(path).read()
- ws = winArabicToUtf8(s)
- (name, ext) = os.path.splitext(path)
- path2 = name + '-utf8' + ext
- file(path2, 'w').write(ws)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement