Newbie question : string processing with RE

Syver Enstad syver at NOSPAMcyberwatcher.com
Wed Mar 28 00:12:03 CEST 2001


<Patrick.Bussi at space.alcatel.fr> wrote in message
news:mailman.985707278.14550.python-list at python.org...

>But when I try to read it again, it acts as if the index of
> a file had to be "rewinded" (e.g. as would do a "seek" on a "true" file).
Yes, that is correct, it is a file object (not a disk file in this case) and
it behaves like a file.
>I
> thought that f3.read was to be considered as a string.
Yes, and no, f3.read() returns a string that is the whole file from the
point in the file where you are to the end. But this means that the next
time you call read on the file it will be at the end and return the empty
string.

If you want to search the string twice you'll have to keep the string
returned by read, like this:

content = f3.read()

Then you can use content as many times as you like.





More information about the Python-list mailing list