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

Change Timezone in CentOS | Thay đổi múi giờ trong CentOS

Timezone of VietNam is Asia/Ho_Chi_Minh. To change default timezone in centos, follow this struction.   mv /etc/localtime /etc/localtime.bak ln -s /usr/share/zoneinfo/Asia/Ho_Chi_Minh /etc/localtime Type date in terminal and you will see time in Viet Nam In Linux, the system time zone is determined by the symbolic link /etc/localtime . This link points to a time zone data file that describes the local time zone. The time zone data files are located at either /usr/lib/zoneinfo or /usr/share/zoneinfo depending on what distribution of Linux you use. For example, on a SuSE system located in New Jersey the /etc/localtime link would point to /usr/share/zoneinfo/US/Eastern . On a Debian system the /etc/localtime link would point to /usr/lib/zoneinfo/US/Eastern . If you fail to find the zoneinfo directory in either the /usr/lib or /usr/share directories, either do a find /usr -print | grep zoneinfo or consult your distribution's do...

Ôn thi !!

Lâu rồi không có cái cảm giác ngồi học đêm tính tính toán toán, ngồi học lại nhớ lại những năm đầu học những môn đại cương phải tính toán nhiều. Giờ thì mình cũng đang học 1 môn đại cương, hix chiều mai thi rồi. Dự định học bao nhiêu mà toàn lười cứ ngồi vào bàn là lại buồn ngủ Nay thì không thể nào mà buồn ngủ được. Lại cộng với đi xem bóng đá làm ly cafe chắc nay thức đến sáng luôn. Có lẽ tầm này là tầm học vào nhất, đọc đâu hiểu luôn không như lúc tối đọc mà chẳng hiểu gì. Cố lên, mai thi xong lại được xả hơi. Thi xong phải đi lên hồ gươm xem mới được. Dạo này cứ lấy cái cớ ngồi học để chẳng đi đâu cả. Nhiều khi cũng bị stress vì mãi mà chằng học được tý gì.Thôi học tiếp nào .....

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