guyskk / guyskk/gitgitgit

编码问题

Aperta
#8 2 commenti 0 reazioni 0 assegnatari Vedi su GitHub
Lingua principale
Python
Stelle
0
Fork
4
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Descrizione

## unicode里面是utf-8编码

```
>>> old = u'\xe9\xa2\x98\xe5\x90\x8d/\xe8\xb4\xa3\xe4\xbb\xbb\xe8\x80\x85:'
>>> [chr(ord(x))for x in old]
['\xe9', '\xa2', '\x98', '\xe5', '\x90', '\x8d', '/', '\xe8', '\xb4', '\xa3', '\
xe4', '\xbb', '\xbb', '\xe8', '\x80', '\x85', ':']
>>> temp=[chr(ord(x))for x in old]
>>> "".join(temp)
'\xe9\xa2\x98\xe5\x90\x8d/\xe8\xb4\xa3\xe4\xbb\xbb\xe8\x80\x85:'
>>> chr

>>> ord

>>> ord('A')
65
>>> ord('a')
97
>>> chr(97)
'a'
```
## unicode 转义

```
>>> s='\u554a\u54c8'
>>> s.decode('unicode-escape')
u'\u554a\u54c8'
```
## html 转义

```
import HTMLParser
import cgi

escape_txt = '<abc>'

#unescape
hp = HTMLParser.HTMLParser()
unescape_txt = hp.unescape(escape_txt )

#escape
escape_txt = cgi.escape(unescape_txt)

http://www.cnblogs.com/xuxn/archive/2011/08/12/parse-html-escape-characters-in-python.html
```

Guida per i contributori

Nessuna guida per i contributori indicizzata per questo repository

Valutazione

Questa issue non è ancora stata valutata.

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.