split

William Park parkw at better.net
Tue May 8 13:10:04 EDT 2001


On Tue, May 08, 2001 at 03:24:00PM +0000, Martin Johansson wrote:
> I have a string s that contains "( 7 Maj 21:58)"
> and i want to save 7 Maj in a variable named date.
> But I dont understand what I suppose to write in the split method.
> date = string.split(s, "( ", ")")

Hmm, to select the 1st and 2nd "whitespace-separated words" (starting
from 0th),
    s = "( 7 Maj 21:58)"
    t = string.split(s)		or	t = s.split() using 2.0+
    date = t[1] + ' ' + t[2]

--William Park, Open Geometry Consulting, Mississauga, Ontario, Canada.
  8 CPU cluster, (Slackware) Linux, Python, LaTeX, vim, mutt




More information about the Python-list mailing list