Last active
February 23, 2022 12:49
-
-
Save gowhari/4f2c9c4eb6fa28c68a71 to your computer and use it in GitHub Desktop.
encoding and decoding
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import quopri | |
print quopri.encodestring('سیب') # '=D8=B3=DB=8C=D8=A8' | |
print quopri.decodestring('=D8=B3=DB=8C=D8=A8') # 'سیب' | |
import HTMLParser | |
unescape = HTMLParser.HTMLParser().unescape | |
print u'سیب'.encode('ascii', 'xmlcharrefreplace') # 'سیب' | |
print unescape('سیب') # 'سیب' | |
import urllib2 | |
print urllib2.quote('سیب') # '%D8%B3%DB%8C%D8%A8' | |
print urllib2.unquote('%D8%B3%DB%8C%D8%A8') # 'سیب' | |
# two times encoded | |
s = 'ÇíÇäå ãÓÇÝÑÈÑí ÔãÇá ÛÑÈ ÔíÑÇÒ ãÓÇÝÑÈÑí ÔÞÇíÞ ÓíÑ' | |
print(s.encode('latin1').decode('cp1256')) | |
s = 'Ù¾Ø§Ø³Ø®Ú¯ÙØ¦Ù 24 ساعت٠دارد.' | |
print(s.encode('latin1').decode('u8')) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment