elearn wrote:
> str='(\\HasNoChildren \\Junk) "/" "[Gmail]/&V4NXPpCuTvY-"'
> x=str.split(' "')
> [i.replace('"','') for i in x]
> ['(\\HasNoChildren \\Junk)', '/', '[Gmail]/&V4NXPpCuTvY-']
>
> x.strip(" ") will create four parts.
>
> is there more simple to do that ?
Here's another way:
>>> s = '(\\HasNoChildren \\Junk) "/" "[Gmail]/&V4NXPpCuTvY-"'
>>> s.replace("(", '"').replace(")", '"').split('"')[1::2]
['\\HasNoChildren \\Junk', '/', '[Gmail]/&V4NXPpCuTvY-']
But you should rather worry about correctness. Can '"' occur inside the
parentheses and vice versa? Is there a way to escape '"'? Can parentheses be
nested? Etc.
The example is not sufficient to specify the problem.
--
https://mail.python.org/mailman/listinfo/python-list