[Tutor] Fwd: thesaurus
Rich Lovely
roadierich at googlemail.com
Thu Jul 9 04:10:10 CEST 2009
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
More information about the Tutor
mailing list