相关疑难解决方法(0)

Python,unicode支持的最佳方法?

我有一个Python应用程序,可以从网站获取多语言信息,并在一个小的GUI窗口(基于wxpython)中显示它们.
我(目前)不在我的源文件中使用任何特定的unicode语句.

现在,当我从Eclipse中运行我的python应用程序时,很好地显示了法语字符(比如ë),当我从py2exe打包版本运行它时,该字符变得不稳定.我真的不明白为什么使用py2exe构建不会产生unicode或编码相关的错误.

但是,要解决这个问题,并按照文章中,我包裹着我的琴弦unicode(my_string, "utf-8")电话只是其输出到屏幕前.这解决了它.

问题:

  • unicode()在显示好方法之前,是否在调用中包装字符串?
  • 为什么没有从Eclipse内部进行unicode转换,而不是从Windows打包的.exe版本转换?

我试过围绕unicode多次缠绕我的脑袋,但似乎我不兼容unicode: - |

python unicode py2exe

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

如何在BeautifulSoup中以unicode呈现标记的内容?

这是来自WordPress帖子详细信息页面的汤:

content = soup.body.find('div', id=re.compile('post'))
title = content.h2.extract()
item['title'] = unicode(title.string)
item['content'] = u''.join(map(unicode, content.contents))
Run Code Online (Sandbox Code Playgroud)

我想div在分配时省略封闭标记item['content'].有没有办法在unicode中呈现标签的所有子标签?就像是:

item['content'] = content.contents.__unicode__()
Run Code Online (Sandbox Code Playgroud)

这将给我一个unicode字符串而不是列表.

python xml screen-scraping web-applications beautifulsoup

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