小编Iva*_*cha的帖子

如何在Python中将HTML非ASCII数据编码为UTF-8

我试着这样做,我发现了这个错误:

>>> import re  
>>> x = 'Ingl\xeas'  
>>> x  
'Ingl\xeas'  
>>> print x  
Ingl?s  
>>> x.decode('utf8')  
Traceback (most recent call last):  
    File "<stdin>", line 1, in <module>  
    File "/usr/lib/python2.6/encodings/utf_8.py", line 16, in decode  
        return codecs.utf_8_decode(input, errors, True)  
UnicodeDecodeError: 'utf8' codec can't decode bytes in position 4-5: unexpected end of data  
>>> x.decode('utf8', 'ignore')  
u'Ingl'  
>>> x.decode('utf8', 'replace')  
u'Ingl\ufffd'  
>>> print x.decode('utf8', 'replace')  
Ingl?  
>>> print x.decode('utf8', 'xmlcharrefreplace')  
Traceback (most recent call last):  
    File "<stdin>", line 1, in <module>  
    File …
Run Code Online (Sandbox Code Playgroud)

python unicode utf-8

2
推荐指数
1
解决办法
9829
查看次数

在Drupal的哪个地方挂钩?

请,

我不能在Drupal中使用钩子,因为我不知道在哪里放置它们.我试图放在template.php中,不成功.

这是我想要使用的钩子:http://api.drupal.org/api/function/hook_form_FORM_ID_alter/6

hook drupal

1
推荐指数
1
解决办法
474
查看次数

标签 统计

drupal ×1

hook ×1

python ×1

unicode ×1

utf-8 ×1