User Profile
Collapse
-
Great, thanks, bvdet. I'll try to incorporate that.... -
It's not much different that is listed above:
[CODE=Python]
import os
import re
dir_name = r'c:\Python25\b ooks\books\book s'
def FindWord(word, fileList):
for file_name in fileList:
for line in file(file_name) .readlines():
if word in line:
print line
def FindWords(wordL ist, fileList):
patt = re.compile('|'. join(wordList),...Leave a comment:
-
Thanks guys.
I got it where it is searching for all the words but I need to fine tune it some more.
First of all, when I put in a word like "eat", it is finding everything with those letters in it like "beat". Is there a way to make it only pull up the exact word?
Also it is bring up all of the lines that have one of the words in it. Is there a way to change it so that it only prints the lines that...Leave a comment:
-
Here is what I have now. It searchs on just fine but when I add a second word it gives me an error. I added a print statement to see if it was splitting the input and it is. I have listed the error I keep getting at the bottom. I can't figure out what is wrong.
Thanks for all your help.
[CODE=PYTHON]
import os
import re
dir_name = r'c:\Python25\b ooks\books\book s'
def FindWord(word,...Leave a comment:
-
Searching for more than one word in multiple files
I have successfully created a program that searches for a word in multiple files but now I need to be able to search by more than one word. I have add code from a previous discussion to my original program but I am unsure how they should fit together. Can someone clear this up for me?
[code=python]
#!C:\PYTHON25\P YTHON.EXE
import os
import re
dir_name= r'c:\Python25\b ooks\books\book s'
word=raw_input( "Enter... -
Sorry, I thought this line in the guidelines and thought I should use Texas22's rather than start an identical one.
"If you wish to post a question do not post it in a discussion created by someone else unless it is about exactly the same problem."
Thanks...Leave a comment:
-
That worked, now I need to work on more than one search word. Thanks!...Leave a comment:
-
I am not sure where to place that so I put it before the loop and got an error that file_name wasn't defined. I placed it inside the loop and it didn't make a difference....Leave a comment:
-
-
I change the second line below to read the lines but I am getting the error message below.
Code:for file_name in entryList: for line in file(file_name).readlines(): if searchWord in line: print line
File "C:/Python25/search.py", line 10, in <module>
for line in file(file_name) .readlines():...Leave a comment:
-
I have the following code. It prints out the list of files inside the folder but doesn't seem to be searching the files.
#!C:\PYTHON25\P YTHON.EXE
import os
dir_name= r'C:\python25\b ooks\books\book s'
entryList=os.li stdir(dir_name)
print entryList
searchWord= "Moses"
for file_name in entryList:
for line in file_name:
if searchWord in line:
...Leave a comment:
-
I'm kind of in Texas22's stage here. You all know what you are talking about but it's all Greek to me. You assume we would know what a glob module is when I don't have the concept of what needs to happen. How can we try it? I don't mean to offend and I really appreciate your help but could you simplify your explanation for us python toddlers?...Leave a comment:
-
-
-
formatting text
I am creating files in a directory and they need to be formatted by month/day format, but I haven't figured out how to format text so that it always shows four numbers.
Can anyone help me out? -
This is awesome. Now, how would I change this so that the files would be named in month,day format like 0101 for January 1st.?...Leave a comment:
No activity results to display
Show More
Leave a comment: