Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- # -*- coding: utf-8 -*-
- # translate2eng_demo.py
- print help(unicode.translate)
- text = u"Åññõýâñçë"
- print
- print text
- test1 = "Test 1 -- String. abc\x150123\x64xyz!\"#$%&\'()*+,-./:;<=>?@[\\]^_`{|}~\xc3"
- test2 = "Test 2 -- abc"+any+".123"
- test3 = "Test 3 -- "It's" 9 > 1 & 3 < 7"
- import string
- print test1
- print ''.join(filter(lambda x: x in string.printable, test1))
- print
- print test2
- print ''.join(filter(lambda x: x in string.printable, test2))
- s= test3
- s = s.replace("&", "&") # Must be done first!
- s = s.replace("'", "'")
- s = s.replace(""", '"')
- s = s.replace("<", "<")
- s = s.replace(">", ">")
- print
- print test3
- print s
- symbols = (u"абвгдеёжзийклмнопрстуфхцчшщъыьэюяАБВГДЕЁЖЗИЙКЛМНОПРСТУФХЦЧШЩЪЫЬЭЮЯÀÁÂÃÄÅÇÈÉÊËÌÍÎÏÏÑÒÓÔÕÖÙÚÛÜÝàáâãäåçèéêëìíîïðñòóóôõöùúûüýÿı",
- u"abvgdeejzijklmnoprstufhzcss_y_euaABVGDEEJZIJKLMNOPRSTUFHZCSS_Y_EUAAAAAAACEEEEIIIIINOOOOOUUUUYaaaaaaceeeeiiiionoooooouuuuyy+")
- print
- print symbols[0]
- print
- print symbols[1]
- print
- tr = {ord(a):ord(b) for a, b in zip(*symbols)}
- text = u'Тëxт çöñвëртëд фрöм Рüщщïåñ тö Ëñглïщх'
- print text.translate(tr)
- text = u'Åññõýâñçë'
- print text.translate(tr)
- text = u'Text converted from English to Russian'
- tr = {ord(a):ord(b) for a, b in zip(*(symbols[1],symbols[0]))}
- print text.translate(tr)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement