seek()
Peter Hansen
peter at engcorp.com
Sun Mar 31 01:31:41 EST 2002
Zutroi Zatatakowski wrote:
>
> Is there a kind of seek() function that does the same thing but except
> of bytes, it seeks for a string? Basically, I want the 5 next bytes
> after a certain string in a file. Example:
> Foo:36.50
> The data I want (36.50) is located on a web page and since the content
> of that page always change, I can't get it with seek() because the bytes
> always change too. I've checked in STRING and RE modules but I can't
> find a function that checks in a file/webpage, they all need input from
> a string.
Well, that's the basic key to writing software: use components
that already exist to build up a more sophisticated solution.
In this case, if you have a method of finding a string in a string
(which you have already found), and you have a method of getting
a string from a file or webpage, you can clearly put the two together
to solve your overall problem.
Getting a string from the data in a file is rather simple, and if
you want to get a string from a web page you should look at the
urllib module.
-Peter
More information about the Python-list
mailing list