这是代码:
print '"' + title.decode('utf-8', errors='ignore') + '",' \
' "' + title.decode('utf-8', errors='ignore') + '", ' \
'"' + desc.decode('utf-8', errors='ignore') + '")'
Run Code Online (Sandbox Code Playgroud)
标题和desc由Beautiful Soup 3(p [0] .text和p [0] .prettify)返回,据我所知,BeautifulSoup3文档是UTF-8编码的.
如果我跑
python.exe script.py > out.txt
Run Code Online (Sandbox Code Playgroud)
我收到以下错误:
Traceback (most recent call last):
File "script.py", line 70, in <module>
'"' + desc.decode('utf-8', errors='ignore') + '")'
UnicodeEncodeError: 'ascii' codec can't encode character u'\xf8' in position 264
: ordinal not in range(128)
Run Code Online (Sandbox Code Playgroud)
但是,如果我跑
python.exe script.py
Run Code Online (Sandbox Code Playgroud)
我没有错.仅在指定输出文件时才会发生.
如何在输出文件中获得良好的UTF-8数据?
我在使用Delphi应用程序作为Windows 7登录屏幕保护程序(对于32位和64位Windows)时遇到问题.即使是空白应用程序(没有任何额外代码的新项目)也会引发错误.
Delphi 7应用程序抛出"内存无法读取"错误,Delphi 2010应用程序抛出"应用程序中发生异常未知软件异常",然后"运行时错误217".在任何表单初始化之前和异常处理程序的任何初始化之前发生此错误.
将notepad.exe设置为登录屏幕保护程序正常.
这里有什么想法吗?