Chuyển đến nội dung chính

unicode with python

str = "Quan h\u1ec7 t\u00ecnh d\u1ee5c v\u00e0 t\u1eadp t\u00ecnh d\u1ee5c c\u00f3 th\u1ec3 g\u00e2y \u0111au tim \u1edf m\u1ed9t s\u1ed1 ng\u01b0\u1eddi n\u1ebfu h\u1ecd kh\u00f4ng th\u01b0\u1eddng xuy\u00ean th\u1ef1c hi\u1ec7n hai ho\u1ea1t \u0111\u1ed9ng \u0111\u00f3"

hic vo duoc cai chuoi nay ma ko biet lam the nao ca??

print u'\u1ec7'
duoc chu "ệ"

print len(u'\u1ec7')
--> 1
print len(unicode('\u1ec7'))
--> 6
vay la convert chuoi thanh unicode the nay moi ky tu lai la 1 ky tu unicode (1Byte)

thu cheat the nay xem sao nhi??
 code = '\u1ec7'
print eval("u'{0}'".format(code))
--> ệ

 su dung regular expression ta se print duoc chuoi dau bai ve dang tieng viet bt
print re.sub(r"(\\u[a-z0-9]{4})", lambda m: eval("u'{0}'".format(m.group(1))), str)

--> Quan hệ tình dục và tập tình dục có thể gây đau tim ở một số người nếu họ không thường xuyên thực hiện hai hoạt động đó

Nhận xét

Bài đăng phổ biến từ blog này

Windows 10 enable long file/folder path

Windows 10 enable long file/folder path Registry Import Enabling Long Paths Windows Registry Editor Version 5.00 [HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control\FileSystem] "LongPathsEnabled"=dword:00000001 [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\FileSystem] "LongPathsEnabled"=dword:00000001 Enable via group policy editor Local Computer Policy -> Computer Configuration -> Administrative Templates -> System -> FileSystem -> Double click Enable Win32 long paths and select Enabled

[Solved] Adobe Premiere Pro CC 2015 has stopped on Windows 10 x64 (card AMD)

First you can check yours graphic card fully support Adobe Premiere Pro CC 2015 at here: http://blogs.adobe.com/premierepro/2013/05/improved-gpu-support-in-adobe-premiere-pro-cc.html If you open "Configure Switchable Graphics", you'll see the adobe premiere pro.exe has been locked. By default, it only run on Intel graphics, so you cant change or unlock this. To make your Adobe Premiere Pro CC 2015 run on AMD Graphics card, just rename file Adobe Premiere Pro.exe into Adobe Premiere Pro CC.exe After rename, run application again, and open Configure Switchable Graphics and choose High Performance. See this thread for more information: https://community.amd.com/thread/167905