s = '[{0},{open({1},r)},{2}]'.format('a', 'b', 'c')
print('--s--', s)
错误:
Traceback (most recent call last):
File "
D:/Work/test2.py
", line 12, in
s = '{0},{open({1},rb)},{2}'.format('a', 'b', 'c')
ValueError: unexpected '{' in field name
解决方法:
不是匹配符号的{} 需要双倍写
s = '[{0},{{open({1},r)}},{2}]'.format('a', 'b', 'c')
print('--s--', s)
>> --s-- [a,{open(b,r)},c]