[Tutor] Fwd: thesaurus

Pete Froslie froslie at gmail.com
Thu Jul 9 04:27:00 CEST 2009


No problem, thanks for taking the time.

I'm actually trying to resolve this error now:

   buff.append(" ".join(lookup(Word) for Word in line.split()))
NameError: global name 'lookup' is not defined

..also assume I need to change 'Word' to something that checks the next word
in the text file and then replaces it with the one that is looked up..
working on that now.

Pete F

On Wed, Jul 8, 2009 at 10:10 PM, Rich Lovely <roadierich at googlemail.com>wrote:

> 2009/7/9 Pete Froslie <froslie at gmail.com>:
> > Great Richard, thanks..
> >
> > I'm getting an error as follows:
> >
> > from __future__ import with_statement
> > SyntaxError: from __future__ imports must occur at the beginning of the
> file
> >
> > I don't think this is the issue in need of rework and have tried a few
> quick
> > reworks.. I'll read up a bit on 'with'
> >
> > cheers
> >
> >
>
> (Appologies for my inital, incomplete email...)
> Oops... forgot it wasn't a standard import...
>
> Just move it to the first line of the program, and delete the relevant
> elif branch.
>
> It won't hurt code on more recent versions.
>
> from __future__ import with_statement
> import sys
>
> buff = []
> with open("path_to_input_file", "r") as fin:
>   for line in fin:
>       buff.append(" ".join(lookup(word) for word in line.split()))
>
> with open("path_to_output_file", "w") as fout:
>   fout.write("\n".join(buff))
>
> --
> Richard "Roadie Rich" Lovely, part of the JNP|UK Famile
> www.theJNP.com
>



-- 
Pete Froslie
617.314.0957
http://www.froslie.net
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20090708/a2ff18ff/attachment.htm>


More information about the Tutor mailing list