2012-06-29 34 views
0

我想將期望參數字典的字符串轉換爲預期字典的鍵列表,例如找到f這樣的:Python:獲取字符串參數

f("some text %(foo)s %(bar)s") == ['foo', 'bar',] # True 

有沒有辦法做到這一點?

+2

擴展http://stackoverflow.com/questions/4839121/檢查-IF-A-字符串到插值 - 提供 - 預期的佔位符,蟒蛇 –

回答

0

如何:

>>> S = "some text %(foo)s %(bar)s" 
>>> print re.findall(r'%\((.*?)\)', S) 
['foo', 'bar']