split

Alex Martelli aleaxit at yahoo.com
Tue May 8 18:06:30 CEST 2001


"Martin Johansson" <045521104 at telia.com> wrote in message
news:kcUJ6.9135$sk3.2548660 at newsb.telia.net...
> 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.

It seems to me that what you want to split on here are
the spaces.  Then you'll need to rejoin the 2nd and 3rd
items in the split:

date = ' '.join(s.split(' ')[1:3])

that's assuming you always have a space before and after
the part that you want, and one in-between, of course.


Alex






More information about the Python-list mailing list