strtok equvialent ?

bonono at gmail.com bonono at gmail.com
Thu Nov 3 12:29:55 CET 2005


thanks.

Fredrik Lundh wrote:
> bonono at gmail.com wrote:
>
> > are there a strtok equivalent in python ? str.split() only takes single
> > seperator.
>
> use a regular expression split with a character group:
>
>     >>> s = "breakfast=spam+egg-bacon"
>     >>> import re
>     >>> re.split("[-+=]", s)
>     ['breakfast', 'spam', 'egg', 'bacon']
>
> to deal with an arbitrary set of delimiting characters without having to
> bother with RE syntax, use re.escape:
>
>     >>> re.split("[" + re.escape("-+=") + "]", s)
>     ['breakfast', 'spam', 'egg', 'bacon']
> 
> </F>




More information about the Python-list mailing list