URGENT: REALLY NEED HELP: Feel Helpless
Peter Otten
__peter__ at web.de
Tue Mar 9 05:37:25 EST 2004
dont bother wrote:
> # python code for creating dictionary of words from an
> input file
> import string, StringIO
> import mailbox, email, re
> import os
> import sys
> import re
> import mailbox
> import email.Parser
> import email.Message
> import getopt
>
>
> fp=open(sys.argv[1], 'r')
>
> msg=email.message_from_file(fp)
>
> msg=msg.get_payload()
>
> dictpos={}
> wordcount={}
> #get rid of anything that isn't a letter, and make it
> all lowercase:
> lower = ''.join(map(chr, range(97, 123)))
> fixed_body = msg.translate(65*' '+lower+6*'
> '+lower+133*' ')
>
> #words_in_body = fixed_body.split()
>
> msg = fixed_body.split()
Throw in a
print msg
sys.exit("debug")
here and see if it's what you expected.
If yes, comment out and proceed.
> for i, w in enumerate(file('dictionary_index')):
> dictpos[w.strip()]=i
> #print i
> #print w
Throw in a
print dictpos
sys.exit("debug")
here and see if it's what you expected.
If yes, comment out and proceed.
> for w in msg:
> try:
> wordcount[w]+=1
> #print wordcount
> except KeyError:
> wordcount[w]=1
> #print wordcount
Throw in a
print wordcount
sys.exit("debug")
here and see if it's what you expected.
If yes, comment out and proceed.
> for w, c in wordcount.iteritems():
> try:
> print dictpos[w],':',c
> except KeyError:
> pass
Throw in a
print [dictpos.get(w, "<not found>") for (w,c) in wordcount.iteritems()]
sys.exit("debug")
here and see if it's what you expected.
If yes, comment out and you've fixed your first python program.
If one step fails, you're at least able to make a more focused post.
But before, please fix your capslock key. This is urgent, too.
Peter
More information about the Python-list
mailing list