File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ with open ("wipe_file.txt" , "w" ) as f :
2+ f .write ("" )
Original file line number Diff line number Diff line change 1+ hello this file is
2+ going to be deleted.
Original file line number Diff line number Diff line change 1+ #------Search for the word irrespective of how its written-----#
2+
3+ word = input ("Enter the word you want to search for in \' Qfile.txt\' : " )
4+
5+ with open ("Qfile.txt" ) as f :
6+ content = f .read ()
7+
8+ if word .lower () in content .lower ():
9+ print (f"The word \' { word } \' is in the \' Qfile.txt\' " )
10+ else :
11+ print (f"The word \' { word } \' is not in the \' Qfile.txt\' " )
12+
Original file line number Diff line number Diff line change 1+ #--------Give the 'line no' for first occurance of given word.
2+ word = input ("Ente the word to get it\' s line no: " )
3+
4+ with open ("Qfile.txt" ) as f :
5+ lines = f .readlines ()
6+
7+ line_no = 1
8+
9+ for line in lines :
10+ if word .lower () in line .lower ():
11+ print (f"The word \' { word } \' is present in line no: { line_no } " )
12+ break
13+ line_no += 1
14+
15+ else :
16+ print (f"The word \' { word } \' is not in the \' Qfile.txt\' " )
17+
You can’t perform that action at this time.
0 commit comments