| | |
Find a word in a file
Please support our Python advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved |
•
•
Join Date: Apr 2006
Posts: 149
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 |
Tag cloud for Python
advanced aliased bash beginner bits calling casino changecolor class clear code command convert corners count csv cturtle cursor definedlines dictionary digital dynamic dynamically events examples excel external file float format frange function gui hints homework i/o iframe import info input java line linux list lists loop matching mouse multiple number numbers obexftp output panel parsing path port prime programming projects py py-mailer py2exe pygame pyqt python random rational raw_input recursion return scrolledtext signal singleton stderr string strings subprocess table tails terminal text thread threading time tkinter tlapse tuple tutorial ubuntu unicode urllib urllib2 valueerror variable web-scrape whileloop windows word wxpython






