string.find does not work in file

Bengt Richter bokr at oz.net
Tue Jun 17 16:37:42 EDT 2003


On Tue, 17 Jun 2003 11:06:32 +0200, =?iso-8859-15?Q?Wolfram_Strau=DF?= <str at iis.fhg.de> wrote:

>Hi,
>I have a problem to run the following lines in a file.
>>
>import string
>f = open('in.txt')
>for l in f.readlines():
>	print string.find(l, '"\n')
The above means if a line does not end with '"\n' print -1 and if
it does end with " print the decimal number that is the count of
characters preceding the '"\n'. Is that what you intended?

To see what the lines really are at that point, why don't you
just add another print statement (indented the same as the one you have) e.g.,
        print repr(l)

If you learn to talk to your interpreter, it will tell you what you need to know
to figure things out ;-)

><
>
>In my python shell (version 2.2.2) on a W2000 system the code finds all 
>lines with the pattern. But running the same code as a python scipt in a 
>shell it does not find any pattern.
>
>If you have any idea, please let me know. Thanks Wolfram
Post actual logs and file snippets, not retyped stuff from memory.
Copy and paste right from the interactive interpreter console window.

Regards,
Bengt Richter




More information about the Python-list mailing list