def somefunc():
    x = 123
y = ['a', 'b']
print('The named args are {}'.format([t[1] for t in Formatter().parse(s) if
    t[1]]))
print('The value of x is {x}, and the list is {y} of len {}'.format(len(y),
    **locals()))
Extract substrings in python