beginner's question
Hadi
hadi at nojunk.com.au
Fri May 14 10:24:04 EDT 2004
Sean,
file-1 contains about 500 lines.
Also when I run the below script, I am getting following error in the
command line:
File "<stdin>", line 1
python test.py
SyntaxError: syntax error
Any suggestion about this?
Thanks again.
hadi
> lexicon = ["our", "list", "of", "words", "to", "be", "compared"]
>
> # open the source and destination files
> src = file("file1/path") # open for reading
> dst = file("file2/path", 'w') # open for writing
>
> # Hadi: does file1 contain one or more lines? This only works for one
line.
> # For more lines, you'll need to do further processing ...
> #
> # Make a list of the words in src. We split the line at each comma, and
> # remove any excess whitespace from around the word
> words = [w.strip() for w in src.readline().split(',')]
>
> # Now we see if the words are in our list and write the results to dst
> for w in words:
> dst.write(str(w in lexicon)) # writes 'True, ' or 'False, '
>
> # Python will eventually close the files for you, or you can do it
> explicitly
> src.close()
> dst.close()
>
>
>
> Hope that helps,
>
> Sean
>
>
More information about the Python-list
mailing list