編集:私は単純なエラーを作成しました'1,2,3 +\nのテスト'は'1,2,3のテスト'+'\n'または'1,2,3のテスト\n'
ファイルから条件付きでテキストを読み取ろうとしています。my_file.readline()をいくつかと比較したときにTrueを返す条件を理解できません
my_file.readline()=='文字列リテラル'は常にfalseを返します。
with open('text.txt','w') as my_file:
my_file.write('testing 1,2,3'+'\n'+'filter me'+'\n') #writing arbitrary text to my file
with open('text.txt','r') as my_file:
str_from_file = my_file.readline() # first line should be 'testing 1,2,3'
print str_from_file == 'testing 1,2,3+\n' #both print False
print str_from_file == 'testing 1,2,3' #what string literal would print true?
print str_from_file
明らかに、私はPythonとコーディングの巨大なナブです。Pythonで5日目です。