0
私は.txtファイルに追加した文にピリオドを追加するループを利用しようとしています。
しかし、私はループを実行するたびに、私の結果は毎回の期間を追加するコードで終了することがわかります。ループエラーを置換する
sentences = input_file.read()
matches = re.finditer("('The dog is happy",sentences,re.MULTILINE)
if matches:
for match in matches:
temp_match = match[1]
sentences = sentences.replace(temp_match, temp_match + '.')
output_file.write(sentences)
input_file.close()
output_file.close()
私は取得していますエラーの例はこれです:
The dog is happy.
The dog is happy..
The dog is happy...
私はこのループを止めるために何ができますか?
'file_contents.replace("犬は幸せです "、"犬は幸せです ")' – jordanm
'file_contents_v2 = file_contents'はファイルの内容を別々にコピーしません。どちらの名前も_same_値を参照します。 –
なぜ文字列の末尾にピリオドを追加する正規表現が必要ですか? –