[TriZPUG] A beginners question I am sure

Philip Semanchuk philip at semanchuk.com
Sun Apr 3 01:06:22 CEST 2011


On Apr 2, 2011, at 6:37 PM, Ken M wrote:

> OK so working on a project (just started) that is for my own academic
> purposes for now.  Just trying to train myself in python.  The attached
> code snippet is to convert the websters dictionary (grab specific
> components) and insert them in a pipe delimmited data file for now.
> Next will be to a database.
> 
> When I ran this for a 4.5 MB snippet of the file it worked fine, output
> file generated output good.  However when I run it for the entirety of
> the webster.txt file (45 MB) the program runs (well more apropos ends
> without any error message to me) but the output file I am creating is
> empty (0 bytes).
> 
> The purpose for now is to build a subset dictionary file that is nothing
> more than word and the single letter initialism for word type (n = noun,
> v = verb, etc.)  Would appreciate insight into why this is not running
> to completion.  If anyone cares to know, I am running this on a Fedora
> 14 box, I edit and created my .py file with vim and my python
> installation is python-2.7-8.fc14.1.i686 (output from rpm -q python).


Coupla comments -- 


At the end, you have this:
fin.close
fout.close

You forgot the parens:
fin.close()
fout.close()

I don't know if that has anything to do with your lack of output. 

For debugging, I'd add this:
   print wordline
after this:
   fout.write(wordline)

to get an idea of whether anything get processed at all. 


And Pythonwise, I'd replace this:
    buildword = ''
    for x in tmpword:
        if x in string.ascii_lowercase:
            buildword = buildword + x

With this:
    buildword = [char for char in tmpword if char in string.ascii_lowercase]
    buildword = ''.join(buildword)



> P.S.  To save bandwidth I did not attach the webster.txt file however if
> anyone wanted to run this against it themselves it can be acquired
> through the Project Gutenberg site.

Do you have a direct link?


Hope this helps
Philip



More information about the TriZPUG mailing list