편집을 True를 반환하지 : 내가해야한다 '1,2,3+ \ n을 테스트'간단한 오류가 만든 '테스트를 1,2,3'+ '\ n'또는파이썬 : 작성한 Readline() == 리터럴 문자열은 결코
'1,2,3 \ n 테스트'은 내가 조건부 파일에서 텍스트를 읽기 위해 노력하고있어.
my_file.readline() == '문자열 리터럴'은 항상 false를 반환 할 때 true를 반환하는 조건을 알아낼 수 없습니다.
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
는 분명히, 나는 코딩 파이썬 &와 거대한 덩어리입니다. 이것은 파이썬으로 5 번째 날입니다.
은 왜'+'가? ''1,2,3 + \ n ''을 테스트하는 것은''1,2,3 \ n '을 테스트하는 것일뿐입니다. " –
오타가 있습니다. 원래 '테스트 1,2,3'+ '\ n' – user1469051