beginner's question

Sean Ross sross at connectmail.carleton.ca
Fri May 14 12:38:42 EDT 2004


"Hadi" <hadi at nojunk.com.au> wrote in message
news:c82kae$auh$1 at lust.ihug.co.nz...
> 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

[snip]
> > # open the source and destination files
> > src = file("file1/path")           # open for reading
> > dst = file("file2/path", 'w')     # open for writing
[snip]


Well, I'm not sure.

Here, I've made a test file called "words.txt" in the same directory where
I'm running the program. The file contains:

our, list, of , words, but, some, are, not, in, the, lexicon

all on one line. so for src I do

src = file("words.txt")

And for dst I create an "output.txt" file

dst = file("output.txt", 'w')

The rest of the program is unmodified, except for the change from str(w in
lexicon) to "%s "%(w in lexicon). When I run the program I receive no
errors, and the output.txt file contains:

True True True True False False False False False False False

So, it appears to work fine over the data (and the manner in which it was
stored) for which it was written. Your data (in file-1) is not stored in the
same way so you'll need to augment the code to handle those differences. To
get more detailed help it would be a good idea to post the code you have
written, give a sample of what file-1 contains, and give an example of what
you want file-2 to look like.

Oh, and there's nothing wrong with helping beginners (a lot of us read this
group hoping to do so), it's just that sometimes it is *more* helpful to
show you how to learn how to do things on your own, rather than giving you
the answers directly. So, when I apologized in that post to Peter, most of
that apology would have been directed towards you - I did you a disservice
by not allowing you to learn how to learn. It may not always seem that way,
when you just want the answers, but it's true, nevertheless.

Sean







More information about the Python-list mailing list