Input.txt ファイル
12626232 : Bookmarks
1321121:
126262
ここで 126262: は任意のテキストまたは数字であるため、基本的に最後の単語が : (コロン) であると検索され、行全体が削除されます。
Output.txt ファイル
12626232 : Bookmarks
私のコード:
def function_example():
fn = 'input.txt'
f = open(fn)
output = []
for line in f:
if not ":" in line:
output.append(line)
f.close()
f = open(fn, 'w')
f.writelines(output)
f.close()
問題: と一致すると : 行全体が削除されますが、それが行末に存在するかどうかを確認したいだけで、行末にある場合は行全体のみを削除します。任意の提案をいただければ幸いです。ありがとう。
私は次のように見ましたが、ここでそれを使用する方法がわかりません
a = "abc here we go:"
print a[:-1]