に複数の空白を確認し、私は、文字列が複数の空白が含まれているかどうかを確認するために、この機能を使用しています:のPython - 文字列
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
関数がTrue
の代わりにFalse
を返す理由がわかりません。
どうすればこの問題を解決できますか?
があなたの後に...何 'プリント(のrepr(テキスト))'のショーを見てくださいスープを介して実行してください –