newbie problem

Manuel Hendel manuel at hendel.net
Tue Aug 27 14:33:49 EDT 2002


On Tue, Aug 27, 2002 at 11:10:14AM -0700, Matt Gerrans wrote:
> How's this (I saved your sample input to a file called c:\temp\input.dat,
> obviously):
> 
> for line in open( r'c:\temp\input.dat' ).readlines():
>    len(line.split()) > 2:
>       if line.split()[0]=='#':
>          tag=line.split()[2]
>       else:
>          print '|'.join([tag]+line.split())
> 
> (This is quick 'n' dirty, of course, if I was *really* going to use it,
> there would be a bit of error handling and it wouldn't be using hard-coded
> filenames, etc., but it is good enough for one-shot use, if you are just
> using it yourself (I think -- you can see how badly it falls apart on your
> real data file!).)

This causes an error in the following line:

len(line.split()) > 2:
                     ^
SyntaxError: invalid syntax

Manuel

-- 
We must overact our part in some measure, in order to produce any effect at 
all. 
-William Hazlitt 




More information about the Python-list mailing list