import re, os, sys
sys.stdout = open('c:\\Fummy_Tasks\\RECONSTR_ANALYSIS\\04052010\\test1_Strings\\log1.txt', 'a')



memdump = open('c:\\Fummy_Tasks\\RECONSTR_ANALYSIS\\04052010\\test1_Strings\\test.txt','rb')
count = 1
while 1:
    memdump_line = memdump.readline()
    if not memdump_line:break
    evidence = open('c:\\Fummy_Tasks\\RECONSTR_ANALYSIS\\04052010\\test1_Strings\\word1.txt','rb')
    for x in range (0,len(memdump_line)-3):
        while 1:
            evidence_line = evidence.readline()
            if not evidence_line:break
            if memdump_line[x]==evidence_line[0] and memdump_line[x+1]==evidence_line[1] and memdump_line[x+2]==evidence_line[2]: 
                    print memdump_line
                    print count
    count = count+1
    evidence.close()
memdump.close()

Please Help!

*****I have in txt:
be and the
help
and jake
jak dkjfh fjhk and
and helo
kjf and and kl
and and

****I have in word1.txt:
and

The output memdump line is only printing with line starting with "and" but I want the code to print everyline where and is located.

PLEASE HELP! i AM NEW IN PYTHON CODE

THANKS

Look i dont get you friend.

Can you explain well again what you want to achieve?

memdump = open('c:\\Fummy_Tasks\\RECONSTR_ANALYSIS\\04052010\\test1_Strings\\test.txt','rb')

Here in test.txt......I have saved the below in each line:

be and the
help
and jake
jak dkjfh fjhk and
and helo
kjf and and kl
and and

evidence = open('c:\\Fummy_Tasks\\RECONSTR_ANALYSIS\\04052010\\test1_Strings\\word1.txt','rb')

Here in word1.txt......I have saved the below:

and

Result Getting now:
1. evidence "and" is only printing in line 0, 3 and 7

WHAT TO DO:
1. Evidence search for "and" in test.txt
to show all lines where and is located in test.txt

PLEASE HELP!

memdump = open('c:\\Fummy_Tasks\\RECONSTR_ANALYSIS\\04052010\\test1_Strings\\test.txt','rb')

Here in test.txt......I have saved the below in each line:

be and the
help
and jake
jak dkjfh fjhk and
and helo
kjf and and kl
and and

evidence = open('c:\\Fummy_Tasks\\RECONSTR_ANALYSIS\\04052010\\test1_Strings\\word1.txt','rb')evidence = open('c:\\Fummy_Tasks\\RECONSTR_ANALYSIS\\04052010\\test1_Strings\\word1.txt','rb')

Here in \\word1.txt......I have saved the below:

and

Result Getting now:
1. evidence "and" is only printing in line 0, 3, 5 and 7

WHAT TO DO:
1. Evidence search for "and" in \\test.txt
to show all lines where "and" is located in \\test.txt

PLEASE HELP!

There are a lot of bugs in your code.
example on line 11

11 evidence = open('c:\\Fummy_Tasks\\RECONSTR_ANALYSIS\\04052010\\test1_Strings\\word1.txt','rb')

You cant do this.` That is you keep opening a file that is already opened.
2. You cant use "rb"flag on a txt. rb is a read binary flag.

I just dont still get you. Do you want to read your file looking for specific words???
I think you need a full re factor.

Try something like

from __future__ import print_function
from os.path import join as pjoin

DIR = pjoin("c:","Fummy_Tasks", "RECONSTR_ANALYSIS", "04052010", "test1_Strings")

def stripped_lines(filename):
    with open(pjoin(DIR, filename), "rb") as fin:
        for line in fin:
            yield line.strip()

def memdump():
    return stripped_lines("test.txt")

def evidence():
    return stripped_lines("word1.txt")

def main(outfile):
    cnt = 0
    for line in memdump():
        for ev in evidence():
            if ev in line:
                cnt += 1
                print(line, file = outfile)
                print(cnt, file = outfile)

if __name__ == "__main__":
    main(open(pjoin(DIR, "log1.txt"), "a"))
import re, os, sys
sys.stdout = open('c:\\Fummy_Tasks\\RECONSTR_ANALYSIS\\04052010\\test1_Strings\\log1.txt', 'a')



memdump = open('c:\\Fummy_Tasks\\RECONSTR_ANALYSIS\\04052010\\test1_Strings\\test.txt')
count = 1
while 1:
    memdump_line = memdump.readline()
    if not memdump_line:break
    evidence = open('c:\\Fummy_Tasks\\RECONSTR_ANALYSIS\\04052010\\test1_Strings\\word1.txt')
       
    for x in range (0,len(memdump_line)-3):
        while 1:
            evidence_line = evidence.readline()
            if not evidence_line:break
            if memdump_line[x]==evidence_line[0] and memdump_line[x+1]==evidence_line[1] and memdump_line[x+2]==evidence_line[2]:
                                       
                    print memdump_line
                    print count
    count = count+1
    evidence.close()
memdump.close()

PLEASE -I need to read file looking for specific words???
For example:
I have in \\test.txt.....words line by line, and I want the program to locate a specific word like "and" in each line and print the line where it is found or located in the memory.

I AM NEW IN PYTHON!!! KINDLY HELP TO AMEND ON MY CODE. PLEASE NOTE: As it is now the code is only printing line that start with "and".
I want the code to print all lines where "and" is located or found in the folderof \\test.txt. That's what I wanted to do. PLEASE HELP!!!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.