Reverse of Python string formatting: generating a dict from a string with
named parameters
I have a string like this:
a = '/stock/%(symbol)s/%(property)s'
I have another string like this, where AAPL and price vary:
b = '/stock/AAPL/price'
I'm trying to generate a dict like this:
c = {
'symbol': 'AAPL',
'property': 'price'
}
With string formatting, I could do a this:
> a % c == b
True
But I'm trying to go the other direction. Time for some regex magic?
No comments:
Post a Comment