search file for tabs

beliavsky at aol.com beliavsky at aol.com
Wed May 3 00:17:53 CEST 2006


Fredrik Lundh wrote:
> beliavsky at aol.com wrote:
>
> > The following code to search a file for tabs does not work, at least on
> > Windows XP. Could someone please tell me what's wrong? Thanks.
> >
> > xfile = "file_with_tabs.txt"
> > for text in open(xfile,"r"):
> >     text = text.strip()
> >     if ("\t" in text):
> >         print text
>
> since you're stripping away all leading and trailing whitespace from each
> line, you'll only find lines that have tabs "in the middle".
>
> (your code is only five lines long.  don't you think you could have double-
> checked each line a couple of times, asking yourself "what exactly is this
> line doing", in less time than it took you to compose the mail ?)

Both your specific and general suggestions are correct. Thanks.




More information about the Python-list mailing list