【问题标题】:Python Unicode Error 'in' StatementPython Unicode Error 'in' 语句
【发布时间】:2015-04-26 02:42:32
【问题描述】:

所以我正在尝试使用检查来查看一个字符串是否在另一个字符串中。但是,其中一个字符串具有 '™' 字符,该字符不在 python 使用的默认 unicode 字符集中。所以我的代码看起来像:

if string in item.name: '''do something'''

其中 item.name 具有商标符号。我如何仍然检查字符串是否在 item.name 中(字符串也可能有商标符号,我想检查一下)。谢谢!

【问题讨论】:

  • “它不在 python 使用的默认 unicode 字符集中” - 是什么让你这么说?
  • 那么现在的问题是什么?您尝试过什么吗?

标签: python unicode decode


【解决方案1】:

using unicodes.

>>> u'™' in u'©™®'
True

【讨论】:

  • 如果你想检查整个字符串是否位于另一个字符串中,第二个字符串是否有商标符号?
  • 为什么你认为一切都会有所不同?
猜你喜欢
  • 2015-03-22
  • 2016-05-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-01-15
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多