Parsing text

Michael Hudson mwh21 at
Sun Nov 28 20:34:53 CET 1999

"Troy" <trekkan at> writes:

> As you will be able to tell, I am new to Python so please forgive any newbie
> things I might do. =)


> What I would like to do is take a variable and parse out each of the
> pieces.  Most commonly delimited by spaces.  Example text:
> This is a test
> I would like to be able to pull out any of "This", "is", "a", "test"
> and be able to drop any element into a variable that I wanted.



Python 1.5.2+ (#12, Nov 19 1999, 15:00:31)  [GCC 2.95.2 19991024 (release)] on linux2
Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam
>>> import string
>>> string.split("This is a test")
['This', 'is', 'a', 'test']

> I hope this explains it enough.  Thanks for any help you may be able
> to provide.
> One other thing, is there a way to tell if a substring exists in a
> string?  in a basic sort of way
> if 'abc' isin '123abc456'


>>> string.find("1122abc33","abc")
>>> string.find("1122abc33","f")

> Something to that effect anyway.

In general

and maybe


> Thanks for your time!

No problem!


More information about the Python-list mailing list