string split

Tino Wildenhain tino at wildenhain.de
Sun Dec 24 05:10:27 EST 2000


Hi Jacek,
...snip...
> is it possible to split not by space (" ") but by "<" and ">" ?
> 
> I need:
> 
> ['one two','<br>','three']
> 
> How to do it in simple way?

You can use the second argument to string.split() as split-string:

split(str [,sep [,maxsplit]]) -> list of strings
splitfields(str [,sep [,maxsplit]]) -> list of strings

Return a list of the words in the string s, using sep as the
delimiter string.  If maxsplit is nonzero, splits into at most
maxsplit words If sep is not specified, any whitespace string
is a separator.  Maxsplit defaults to 0.

Anyway, using sgmllib or htmllib could be much more convenient.

Regards
Tino




More information about the Python-list mailing list