【发布时间】:2018-03-03 18:42:50
【问题描述】:
我正在使用这个函数来检查一个字符串是否包含多个空格:
def check_multiple_white_spaces(text):
return " " in text
它通常工作正常,但在以下代码中却没有:
from bs4 import BeautifulSoup
from string import punctuation
text = "<p>Hello world!!</p>\r\n\r"
text = BeautifulSoup(text, 'html.parser').text
text = ''.join(ch for ch in text if ch not in set(punctuation))
text = text.lower().replace('\n', ' ').replace('\t', '').replace('\r', '')
print check_multiple_white_spaces(text)
text 变量的最终值为hello world,但我不知道为什么check_multiple_white_spaces 函数返回的是False 而不是True。
我该如何解决这个问题?
【问题讨论】:
-
看看
print(repr(text))显示的内容......在你喝完汤之后
标签: python string python-2.7 beautifulsoup whitespace