+2

Python 3 reading txt file

I got txt file called RR.txt that has On and Off words so i want my program to read txt file and if there is word On in first line it will print("On") Can someone please help me I have been trying for 1 hour and it didn't work. RR.txt: Mode: On Ww: Off

4/12/2019 1:38:09 PM

Damjan Boxer

3 Answers

New Answer

+14

Please upload your code so I can understand the problem

+13

Anna I think he should provide the code so he can learn something out of it. Just a personel opinion didn't want to hurt anyone.

+4

with open('rr.txt', 'rt') as f: for line in f: if line.strip() == 'On': print('on') else: print('off') break alternative to the third line: if 'On' in line.strip(): (if there's more text in the first line than just 'On')