search file for tabs

Fredrik Lundh fredrik at pythonware.com
Tue May 2 18:02:20 EDT 2006


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 ?)

</F>






More information about the Python-list mailing list