我正在使用python 2.6.5我想写一些日文字符到一个文件.我收到此错误,我不知道如何更改编码.
Python 2.6.5 (r265:79063, Jun 12 2010, 17:07:01)
[GCC 4.3.4 20090804 (release) 1] on cygwin
>>> s = u'\u5E73\u621015'
>>> with open("yop", "wb") as f:
... f.write( s + "\n" );
...
Traceback (most recent call last):
File "<stdin>", line 2, in <module>
UnicodeEncodeError: 'ascii' codec can't encode characters in position 0-1:
ordinal not in range(128)
>>> type( s )
<type 'unicode'>
Run Code Online (Sandbox Code Playgroud) 如何从Python中删除字符串中的所有HTML?例如,我该怎么转:
blah blah <a href="blah">link</a>
Run Code Online (Sandbox Code Playgroud)
成
blah blah link
Run Code Online (Sandbox Code Playgroud)
谢谢!