[Tutor] Help Me!! Need help with python
Andrei Kulakov
ak@silmarill.org
Wed, 22 May 2002 20:16:09 -0400
On Wed, May 22, 2002 at 08:38:24PM +0800, Charlie Chen wrote:
> Hi,
>
> I am trying to search a text file with a specified string,and i am having trouble doing it.
> I tried with re, and having lots of trouble
> for example if a text contain strings "abc" it will print out all the string starting with abc.
>
> Can you give me some hint on doing this in Python.
>
Here's an example:
>>> s = "some text here"
>>> if s.find("here") != -1: print "There is a 'here' in this string."
...
There is a 'here' in this string.
s.find returns position of found substring. If it's at the beginning, it
returns 0. When not found, it gives back -1, so that's what you have to test
for.
- Andrei
>
> Thanks
>
> Charlie
> --
> _______________________________________________
> Sign-up for your own FREE Personalized E-mail at Mail.com
> http://www.mail.com/?sr=signup
>
>
>
> _______________________________________________
> Tutor maillist - Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
--
Cymbaline: intelligent learning mp3 player - python, linux, console.
get it at: cy.silmarill.org