| | |
Find a word in a file
Please support our Python advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved |
•
•
Join Date: Apr 2006
Posts: 148
Reputation:
Solved Threads: 40
•
•
•
•
I want to see if a certain word is in a text file, how do I go about that?
Python Syntax (Toggle Plain Text)
for line in open("file"): if "word" in line: do_something(line)
you can read in one whole chunk
Python Syntax (Toggle Plain Text)
data = open("file").read() if "someword" in data: do_something()
![]() |
Similar Threads
- Find word in file!! (C++)
- find strings in file.txt (C++)
- Scan text file to find all words of 4 characters or less (Shell Scripting)
- Searching a file for a string (C++)
- about:blank hijack (can't find any .dll-file) (Viruses, Spyware and other Nasties)
Other Threads in the Python Forum
- Previous Thread: Python tuples and Sql query
- Next Thread: Problem with threads
| Thread Tools | Search this Thread |
advanced aliased bash beginner bits calling casino changecolor class clear command convert corners count csv cturtle cursor def definedlines dictionary digital dynamic dynamically events examples external file float format frange function google gui hints homework i/o iframe import info input java line linux list lists loop matching mouse multiple number numbers obexftp output parsing path port prime programming projects py py2exe pygame pygtk python random rational raw_input recursion return scrolledtext signal singleton skinning stderr string strings subprocess table tails terminal text thread threading time tkinter tlapse tuple tutorial ubuntu unicode urllib urllib2 valueerror variable voip web-scrape whileloop windows word wxpython






