parse data

MooMaster ntv1534 at gmail.com
Wed Nov 9 11:10:24 EST 2005


If you know the indices of where the data should be in your string, you
can use substrings... ie:

>>> stringy = " Happy Happy Cow, 50, 1234 Your Mom's House AllTheTime,USA "
>>> stringy[0:16]
' Happy Happy Cow'

If the data isn't set all the time (for example, and address doesn't
have a mandatory length), then you're probably stuck using the index
function...unless you have everything separated by a delimiter, such as
a ","...then this would work:

>>> listy = stringy.split(",")
>>> print listy
[' Happy Happy Cow', ' 50', " 1234 Your Mom's House AllTheTime", 'USA
']


Hope this helps!




More information about the Python-list mailing list