splitting using '\' as a delimiter

Chris Liechti cliechti at gmx.net
Sun Dec 2 19:21:32 EST 2001


[posted and mailed]

"Peoter Veliki" <peoter_veliki at hotmail.com> wrote in 
news:mailman.1007336463.14815.python-list at python.org:
> I have strings like this:
> string = 'value\key'
> that I would like to split.  If I try splitting the string like this:
> alias = string.split('\\',string)
> I get:
> alias = ['\']    


change the order of arguments:
>>> string.split('value\\key','\\')
['value', 'key']

or:

>>> 'value\\key'.split("\\")
['value', 'key']

sidenote: don't name your variable "string", that would hide the module 
with the same name.

chris

> How can I do this?
> 
> Thanks
> 



-- 
Chris <cliechti at gmx.net>




More information about the Python-list mailing list