thanks this solve the error but running the code produces another error ie
index out of range.
Traceback (most recent call last):
File "C:\Python25\myscript\log\readfile9.py", line 22, in <module>
if line[3] == pattern:
IndexError: list index out of range
> To: [email protected]
> From: [email protected]
> Date: Sun, 9 Jan 2011 14:07:39 +0000
> Subject: Re: [Tutor] Open a text file, read and print pattern matching
>
>
> "tee chwee liong" <[email protected]> wrote
>
> > i got syntax error when running this line:
> > data = for line in open(filename) if not line.startswith("#")
>
> Should be:
>
> data = [ line for line in open(filename) if not line.startswith("#") ]
>
> Notice the extra line at the beginning and the fact that it is
> surrounded by [] which makes it a *list comprehension*.
>
>
> But that won't help if you can't put commment markers
> at the front... But you might get away with:
>
> data = [ line for line in open(filename) if '-1' in line ]
>
> HTH,
>
> --
> Alan Gauld
> Author of the Learn to Program web site
> http://www.alan-g.me.uk/
>
>
> _______________________________________________
> Tutor maillist - [email protected]
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
_______________________________________________
Tutor maillist - [email protected]
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor