User Profile

Collapse

Profile Sidebar

Collapse
grantstech
grantstech
Last Activity: Jul 17 '07, 09:57 PM
Joined: Jun 14 '07
Location:
  •  
  • Time
  • Show
  • Source
Clear All
new posts

  • Great, thanks, bvdet. I'll try to incorporate that....
    See more | Go to post

    Leave a comment:


  • 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),...
    See more | Go to post

    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...
    See more | Go to post

    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,...
    See more | Go to post

    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...
    See more | Go to post

  • grantstech
    replied to searching for words in a file
    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...
    See more | Go to post

    Leave a comment:


  • grantstech
    replied to searching for words in a file
    That worked, now I need to work on more than one search word. Thanks!...
    See more | Go to post

    Leave a comment:


  • grantstech
    replied to searching for words in a file
    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....
    See more | Go to post

    Leave a comment:


  • grantstech
    replied to searching for words in a file
    None of the files have a space in the name....
    See more | Go to post

    Leave a comment:


  • grantstech
    replied to searching for words in a file
    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
    Traceback (most recent call last):
    File "C:/Python25/search.py", line 10, in <module>
    for line in file(file_name) .readlines():...
    See more | Go to post

    Leave a comment:


  • grantstech
    replied to searching for words in a file
    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:
    ...
    See more | Go to post

    Leave a comment:


  • grantstech
    replied to searching for words in a file
    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?...
    See more | Go to post

    Leave a comment:


  • grantstech
    replied to formatting text
    Thanks, I get it now....
    See more | Go to post

    Leave a comment:


  • grantstech
    replied to writing to a file in python
    Thank you, thats a big help....
    See more | Go to post

    Leave a comment:


  • grantstech
    started a topic formatting text

    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?
    See more | Go to post

  • grantstech
    replied to writing to a file in python
    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.?...
    See more | Go to post

    Leave a comment:

No activity results to display
Show More
Working...