Parsing Strings in Enclosed in Curly Braces
Mike Driscoll
kyosohma at gmail.com
Fri May 15 12:23:31 EDT 2009
On May 15, 11:12 am, xama... at yahoo.com wrote:
> How do you parse a string enclosed in Curly Braces?
>
> For instance:
>
> x = "{ABC EFG IJK LMN OPQ}"
>
> I want to do x.split('{} ') and it does not work. Why does it not work
> and what are EXCEPTIONS to using the split method?
>
> That I want to split based on '{', '}' and WHITESPACE.
>
> Please advise.
>
> Regards,
> Xav
The reason it doesn't work is that you don't have a string with "{}".
Instead, you have one of each. If your string was like this, then it
would split:
x = "{} ABC EFG"
In the mean time, you can just use some string slicing like this:
y = x[1:-1]
That will remove the braces and allow you to manipulate the text
therein.
- Mike
More information about the Python-list
mailing list