output = open('d:\code\\output.txt','w')

for y in range (0,len(evidence_array)):
    output.write(evidence_array[y] + ', ' + found[y] + '\n') #I am not sure if this output writing is correct!
output.close()

PLEAE CAN SOMEONE HELP! ---I AM NOT SURE IF THIS OUTPUT WRITING IS CORRECT

THANKS

Use an editor program like notepad or IDLE to look at the contents of file output.txt

##########################
# WRD
##########################

import re, os, sys

evidence = open('c:\\22042010\\log1.txt', 'r')

count = 1
evidence_array = ''
found = []
##############################
### WE START BY READING ALL OF THE TEXT TO SEARCH FOR INTO THE ARRAY
##############################
while 1:
    temp_line = evidence.readline()
    evidence_array = evidence_array + temp_line
    if not temp_line:break

##############################
### WE THEN ZERO OUT AN ARRAY TO COUNT ELEMENTS
##############################
for y in range (0,len(evidence_array)):
    found.append(0)

evidence.close()


memdump = open('c:\\22042010\\2708.txt','rb')
while 1:
    memdump_line = memdump.readline()
    if not memdump_line:break
    for x in range (0,len(memdump_line)-10):
    for y in range (0,len(evidence_array)-10):
        if memdump_line[x]==evidence_array[y] and memdump_line[x+1]==evidence_array[y+1] and memdump_line[x+2]==evidence_array[y+2] and memdump_line[x+3]==evidence_array[y+3] and memdump_line[x+4]==evidence_array[y+4] and memdump_line[x+5]==evidence_array[y+5]and memdump_line[x+6]==evidence_array[y+6] and memdump_line[x+7]==evidence_array[y+7]and memdump_line[x+8]==evidence_array[y+8] and memdump_line[x+9]==evidence_array[y+9] and memdump_line[x+10]==evidence_array[y+10]: 
            for z in range (0,10):
                found[y+z]=found[y+z]+1
                break
                
    count = count+1
memdump.close()

output = open('c:\\Fummy_Tasks\\22042010\\test1_Strings\\output.txt','w')

for y in range (0,len(evidence_array)):
    output.write(evidence_array[y] + ', ' + found[y] + '\n') #I am not sure if this output writing is correct!
output.close()

I get the following error message:


Traceback (most recent call last):
File "C:/Python26/03062010- EVI_WRD_TEST_LOG1.py", line 53, in <module>
output.write(evidence_array[y] + ', ' + found[y] + '\n') #I am not sure if this output writing is correct!
TypeError: cannot concatenate 'str' and 'int' objects

would you please help me with this problem?

FOREN

I think this should do it.

output.write('%s, %s\n' % (evidence_array[y], found[y])

I get the following output result...which is not adding the character count as expected....

U, 0
n, 0
i, 0
t, 0
e, 0
d, 0
, 0
t, 0
o, 0
p, 0
, 0
w, 0
o, 0
r, 0
l, 0
d, 0
, 0
r, 0
i, 0
c, 0
h, 0
, 0
l, 0
i, 0
s, 0
t, 0
, 0
d, 0
e, 0
s, 0
p, 0
i, 0
t, 0
e, 0
, 0
£, 0
7, 0
0, 0
0, 0
m, 0
, 0
d, 0
e, 0
b, 0
t, 0

, 0
M, 0
A, 0
N, 0
C, 0
H, 0
E, 0
S, 0
T, 0
E, 0
R, 0
, 0
U, 0
n, 0
i, 0
t, 0
e, 0
d, 0
, 0
h, 0
a, 0
v, 0
e, 0
, 0
b, 0
e, 0
e, 0
n, 0
, 0
v, 0
a, 0
l, 0
u, 0
e, 0
d, 0
, 0
a, 0
s, 0
, 0
t, 0
h, 0
e, 0
, 0
b, 0
i, 0
g, 0
g, 0
e, 0
s, 0
t, 0
, 0
f, 0
o, 0
o, 0
t, 0
b, 0
a, 0
l, 0
l, 0
, 0
c, 0
l, 0
u, 0
b, 0
, 0
i, 0
n, 0
, 0
t, 0
h, 0
e, 0
, 0
w, 0
o, 0
r, 0
l, 0
d, 0
., 0

, 0
T, 0
h, 0
e, 0
, 0
O, 0
l, 0
d, 0
, 0
T, 0
r, 0
a, 0
f, 0
f, 0
o, 0
r, 0
d, 0
, 0
s, 0
i, 0
d, 0
e, 0
,, 0
, 0
w, 0
h, 0
o, 0
, 0
a, 0
r, 0
e, 0
, 0
m, 0
o, 0
r, 0
e, 0
, 0
t, 0
h, 0
a, 0
n, 0
, 0
£, 0
7, 0
0, 0
0, 0
m, 0
i, 0
l, 0
l, 0
i, 0
o, 0
n, 0
, 0
i, 0
n, 0
, 0
d, 0
e, 0
b, 0
t, 0
,, 0
, 0
h, 0
e, 0
l, 0
d, 0
, 0
o, 0
n, 0
, 0
t, 0
o, 0
p, 0
, 0
s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

Please can someone help!
I want to count the block of evidence for example:
top world rich list despite.docx

413
top world rich list des

451
op world rich

455
orld rich list despite

460
top world rich list despite.doc

481
top world rich list despite.docx

488
ited top world rich list despite.docx

495
rich list despite.docx

501
United top world rich list despite.docx

516
h list despite.doc

MY CODE IS THIS AND WITH NO RESULT....CAN SOMEONE HELP PLEASE....

import re, os, sys

mkdir_name = 'mkdir c:\\22042010-EVIDENCE_WOR' 
print mkdir_name
os.system(mkdir_name)


import re, os, sys
sys.stdout = open('c:\\22042010-EVIDENCE_WOR\\log1.txt', 'a')

count = 1
while 1:
    evidence_line = evidence.readline()
    if not evidence_line:break
    for y in range (0,len(evidence_line)-10):
        if evidence_line[y] and evidence_line[y+1] and evidence_line[y+2] and evidence_line[y+3] and evidence_line[y+4] and evidence_line[y+5]and evidence_line[y+6] and evidence_line[y+7]and evidence_line[y+8] and evidence_line[y+9] and evidence_line[y+10]:
            print count
    count = count+1
evidence.close()

What you want to count? I do not understand what you are trying to accomplish. Why import same things two times. What you think to accomplish by opening sys.stdin for append?

THIS IS WHAT I WANT TO COUNT

I want to count the block of evidence for example:

413
top world rich list des

451
op world rich

455
orld rich list despite

460
top world rich list despite.doc

481
top world rich list despite.docx

488
ited top world rich list despite.docx

495
rich list despite.docx

501
United top world rich list despite.docx

516
h list despite.doc

Sum of the numbers in file?

No...please

i want to count word, lines and char in file

I posted here earlier link to letter count post:

If you want to count something from file see this:
http://www.daniweb.com/forums/post65...tml#post658840

For lines, you count '\n' characters in file.
For words, you split the lines to words from white space with split().

please I am still new in PYTHON, JUST TRYING...
CAN YOU SEND STEPS TO FOLLOW PLS?

Link did not copy well, but it was OK in earlier post:
http://www.daniweb.com/forums/post658840.html#post658840

It is not even needed if you want total count of letters in file

Here is example from string giving all three counts, not individual letter counts, which you can see in the above post.

inputstring="""top world rich list despite.docx
413
top world rich list des

451
op world rich

455
orld rich list despite

460
top world rich list despite.doc

481
top world rich list despite.docx

488
ited top world rich list despite.docx

495
rich list despite.docx

501
United top world rich list despite.docx

516
h list despite.doc
"""

charcount, linecount, wordcount = len(inputstring), inputstring.count('\n'), len(inputstring.split())
print('String has %i characters in %i lines, total number of words is %i' % (charcount,linecount,wordcount))
print('Words are:\n %s' % inputstring.split())
uniqwords=set(inputstring.lower().split())
print('The %i unique words are: %s' % (len(uniqwords),uniqwords))

""" Output:
String has 323 characters in 27 lines, total number of words is 54
Words are:
 ['top', 'world', 'rich', 'list', 'despite.docx', '413', 'top', 'world', 'rich', 'list', 'des', '451', 'op', 'world', 'rich', '455', 'orld', 'rich', 'list', 'despite', '460', 'top', 'world', 'rich', 'list', 'despite.doc', '481', 'top', 'world', 'rich', 'list', 'despite.docx', '488', 'ited', 'top', 'world', 'rich', 'list', 'despite.docx', '495', 'rich', 'list', 'despite.docx', '501', 'United', 'top', 'world', 'rich', 'list', 'despite.docx', '516', 'h', 'list', 'despite.doc']
The 22 unique words are: {'451', 'despite', '455', 'despite.doc', '495', 'despite.docx', 'united', 'top', 'rich', '501', '460', 'orld', '488', 'world', '481', 'h', 'des', 'list', '413', 'ited', 'op', '516'}
"""

You may need to refine the definition of word (numbers count or not), if you want whitespace in character count.

I DID IT LIKE THIS AND IT FINE ....MANY THANKS

import re, os, sys

inputstring = open('c:\\22042010-EVIDENCE_WOR\\log1.txt', 'a')

charcount, linecount, wordcount = len(inputstring), inputstring.count('\n'), len(inputstring.split())

print ('String has %i characters in %i lines, total number of words is %i' %(charcount, linecount, wordcount))

Are you going to add text to log1.txt as you opened it for append ('a') instead of read ('r', the default if mode missing)? Also the lines have nothing from modules re, os or sys, so no need to import them.

You did not read in the file also.

inputstring = open('c:\\22042010-EVIDENCE_WOR\\log1.txt').read()
charcount, linecount, wordcount = len(inputstring), inputstring.count('\n'), len(inputstring.split())
print ('String has %i characters in %i lines, total number of words is %i' %(charcount, linecount, wordcount))

PLEASE THERE IS A PROBLEM....
I THINK THE PROGRAM IS COUNT ALL LINE IN THE INPUTSTRING. WHAT I WANT TO COUNT IS ONLY THE BLOCK OF EVIDENCE IN LINE AND NOT THE NUMBER.. I.E

488 (i DO NOT WANT THIS TO COUNTED)
ited top world rich list despite.docx (I ONLY WANT TO COUNT THE LINE IN BLOCK OF EVIDENCE)

CAN YOU HELP PLEASE!

No!

Text is saved in the log1.txt and i want to read only the char in line not the line numbers.

Permalink 18 Minutes Ago 
 0  Re: Python evidence output writingAre you going to add text to log1.txt as you opened it for append ('a') instead of read ('r', the default if mode missing)? Also the lines have nothing from modules re, os or sys, so no need to import them.

You did not read in the file also.


Python Syntax (Toggle Plain Text)
inputstring = open('c:\\22042010-EVIDENCE_WOR\\log1.txt').read()charcount, linecount, wordcount = len(inputstring), inputstring.count('\n'), len(inputstring.split())print ('String has %i characters in %i lines, total number of words is %i' %(charcount, linecount, wordcount))inputstring = open('c:\\22042010-EVIDENCE_WOR\\log1.txt').read()
charcount, linecount, wordcount = len(inputstring), inputstring.count('\n'), len(inputstring.split())
print ('String has %i characters in %i lines, total number of words is %i' %(charcount, linecount, wordcount))

NO!
TEXT IS SAVED IN LOG1.TXT
AND i ONLY NEED TO COUNT THE LINE WHERE EVIDENCE APPEARS AND NOT THE NUMBER OF THE EVIDENCE LINE.

PLEASE YOUR HELP IS GREATLY NEEDED...

This does not count empty lines and lines with numbers only.

from __future__ import print_function # to work with Python 3 also use print function
import string
inputstring = open('test.txt').read()

inputlines =inputstring.split('\n')
inputlines =[ line for line in inputlines if line.strip(string.digits + string.whitespace)] # leave out lines with only numbers and/or whitespace
linecount = len(inputlines)
lines = '\n'.join(inputlines) # linefeeds back

charcount, linecount, wordcount = len(lines), linecount, len(lines.split())

print ('String has %i characters in %i lines, total number of words is %i.' %(charcount, linecount, wordcount))

uniqwords=set(lines.lower().split())
print()
print('The %i unique words are: %s' % (len(uniqwords),sorted(uniqwords)))
""" Output:
String has 278 characters in 10 lines, total number of words is 45.

The 13 unique words are: ['des', 'despite', 'despite.doc', 'despite.docx', 'h', 'ited', 'list', 'op', 'orld', 'rich', 'top', 'united', 'world']
"""

Please what is your name and your contact? Can you please send it accross to me. Please i need to know you the more. The code is good for me. With many thanks.

top world rich list despite.docx


413
top world rich list des


451
op world rich  


455
orld rich list despite


460
 top world rich list despite.doc


481
top world rich list despite.docx


488
ited top world rich list despite.docx


495
 rich list despite.docx


501
United top world rich list despite.docx


516
h list despite.doc


523
 rich list despite.docx


1501
nited top world rich list despite.docx


1504
rich list despite.docx


1509
world rich list despite.docx


1512
orld rich list despite.docx


1535
 top world rich list despite


1541
d rich list despite.docx


1545
orld rich list despite.docx


1575
ted top world rich list despite.docx


1584
list despite.doc


5914
that top 20 is


44693
United top world rich list despite.docx


59701
from England - despite 


59763
the Premier League being the most indebted in Europe, according to governing body Uefa.


59764
MANCHESTER United have been valued as the biggest football club in the world.


59768
The Old Trafford side, who are more than 


59769
700million in debt, held on top spot in Forbes Magazine'


59770
s list of the world'


59771
s 20 most valuable football teams. Six of that top 20 are 


59772
United top world rich list despite 


59776
700m debt


59777
the Premier League being the most indebted in Europe, according to governing body Uefa.s Magazine'


59778
700million in debt, held on top spot in Forbes Magazine


77806
s list of the world


77807
s 20 most valuable football teams. Six of </w:t></w:r><w:proofErr w:type="gramStart"/><w:r><w:rPr><w:lang w:val="en-GB"/></w:rPr><w:t>that top 20 are</w:t></w:r><w:proofErr w:type="gramEnd"/><w:r><w:rPr><w:lang w:val="en-GB"/></w:rPr><w:t xml:space="preserve"> from England 


77808
 despite the Premier League being the most indebted in Europe, according to governing body Uefa.</w:t></w:r></w:p><w:sectPr w:rsidR="006F03F8" w:rsidRPr="006F03F8" w:rsidSect="00A803D6"><w:pgSz w:w="12240" w:h="15840"/><w:pgMar w:top="1440" w:right="1440" w:bottom="1440" w:left="1440" w:header="708" w:footer="708" w:gutter="0"/><w:cols w:space="708"/><w:docGrid w:linePitch="360"/></w:sectPr></w:body></w:document>


77809
United top world rich list despite


85566
League being the most indebted in Europe, according to governing body Uefa.re  i  Fofrom England '


101515
the Premier L


101517
League being the most indebted in Europe, according to governing body Uefa.re  i  Fofrom England '


101519
the Premier L


101521
League being the most indebted in Europe, according to governing body Uefa.re  i  Fofrom England 


106212
the Premier L


106214
League being the most indebted in Europe, according to governing body Uefa.re  i  Fofrom England 


106217
the Premier L


106219
 despite the Premier League being the most indebted in Europe, according to governing body Uefa.


106401
le football teams.


106402
op world rich list despite.docx


128952
p world rich list despite.docx


129682
rich list despite.docx


129695
op world rich list despite.docx


130687
 rich list despite.docx


132166
ist despite: 


132217
 list despite: 


132219
p world rich list despite.docx


135787
according to


146491
top world rich list despite.docx


413
top world rich list des


451
op world rich  


455
orld rich list despite


460
 top world rich list despite.doc


481
top world rich list despite.docx


488
ited top world rich list despite.docx


495
 rich list despite.docx


501
United top world rich list despite.docx


516
h list despite.doc


523
 rich list despite.docx


1501
nited top world rich list despite.docx


1504
rich list despite.docx


1509
world rich list despite.docx


1512
orld rich list despite.docx


1535
 top world rich list despite


1541
d rich list despite.docx


1545
orld rich list despite.docx


1575
ted top world rich list despite.docx


1584
list despite.doc


5914
that top 20 is


44693
United top world rich list despite.docx


59701
from England - despite 


59763
the Premier League being the most indebted in Europe, according to governing body Uefa.


59764
MANCHESTER United have been valued as the biggest football club in the world.


59768
The Old Trafford side, who are more than 


59769
700million in debt, held on top spot in Forbes Magazine'


59770
s list of the world'


59771
s 20 most valuable football teams. Six of that top 20 are 


59772
United top world rich list despite 


59776
700m debt


59777
the Premier League being the most indebted in Europe, according to governing body Uefa.s Magazine'


59778
700million in debt, held on top spot in Forbes Magazine


77806
s list of the world


77807
s 20 most valuable football teams. Six of </w:t></w:r><w:proofErr w:type="gramStart"/><w:r><w:rPr><w:lang w:val="en-GB"/></w:rPr><w:t>that top 20 are</w:t></w:r><w:proofErr w:type="gramEnd"/><w:r><w:rPr><w:lang w:val="en-GB"/></w:rPr><w:t xml:space="preserve"> from England 


77808
 despite the Premier League being the most indebted in Europe, according to governing body Uefa.</w:t></w:r></w:p><w:sectPr w:rsidR="006F03F8" w:rsidRPr="006F03F8" w:rsidSect="00A803D6"><w:pgSz w:w="12240" w:h="15840"/><w:pgMar w:top="1440" w:right="1440" w:bottom="1440" w:left="1440" w:header="708" w:footer="708" w:gutter="0"/><w:cols w:space="708"/><w:docGrid w:linePitch="360"/></w:sectPr></w:body></w:document>


77809
United top world rich list despite


85566
League being the most indebted in Europe, according to governing body Uefa.re  i  Fofrom England '


101515
the Premier L


101517
League being the most indebted in Europe, according to governing body Uefa.re  i  Fofrom England '


101519
the Premier L


101521
League being the most indebted in Europe, according to governing body Uefa.re  i  Fofrom England 


106212
the Premier L


106214
League being the most indebted in Europe, according to governing body Uefa.re  i  Fofrom England 


106217
the Premier L


106219
 despite the Premier League being the most indebted in Europe, according to governing body Uefa.


106401
le football teams.


106402
op world rich list despite.docx


128952
p world rich list despite.docx


129682
rich list despite.docx


129695
op world rich list despite.docx


130687
 rich list despite.docx


132166
ist despite: 


132217
 list despite: 


132219
p world rich list despite.docx


135787
according to


146491
eague being the most indebted in Europe, according to governing body Uefa.g body Uefa.s Magazine'


348436
of the world's 20 most valuablLeague being the most indebted in Europe, according to governing body Uefa.


353726
according to


492626
 have been removed, had its name changed, or is temporarily unavailable.</h3>


898860
top world rich list despite.lnk


987075
top world rich list despite.docx


2556850
d rich list despite.docx


2640098
top world rich list despite.docx


2658928
d rich list despite.docx


2675459
 world rich list despite.docx


2679307
 world rich list despite.docx


2686414
top world rich list despite.docx


2711215

PLEASE FROM THIS STRING TEXT, HOW CAN I WRITE A PYTHON CODE TO LOCATE AND COUNT THE DISPERSAL EVIDENCE.


import stringinputstring = open('test.txt').read() inputlines =inputstring.split('\n')

PLEASE WHAT WILL I DO NEXT....

You are doing criminalistics?

Not all. This is sample research work on task given using info on metro daily news

You think becos i use the word evidence. It is simply a research work on task given. I dont want to use excel for the result that's why i am learning about python

you must formulate your problem first in pseudocode and then turn it to program.

import string
inputstring = open('test.txt').read() 
inputlines =inputstring.split('\n')inputlines =[ line for line in inputlines if line.strip(string.digits + string.whitespace)] 
linecount = len(inputlines)lines = '\n'.join(inputlines) # linefeeds back charcount, linecount, wordcount = len(lines), linecount, len(lines.split()) 
print ('String has %i characters in %i lines, total number of words is %i.' %(charcount, linecount, wordcount))

this is what was used but no good result for the dispersal evidence

I really don't get what you trying to do. It seems some esay thing with the data of some file. But I just don't get what.

Sum of numbers, ordering of the numbers, listing the average of the numbers, just listing the numbers...

I really don't know what.

And the CAPS are not needed, I believe the most of the people here is able to read your posts without them.

I want to list the numbers, sum of numbers and average of the numbers from the sample output texts. Unique word is found from the output texts. I just think I should list the dispersal word from the sample output texts. With many thanks.

Define: "dispersal word"

Earlier you said you wanted to ignore numbers.

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.