1
msg = '{"event":"addChannel","channel":"ok_sub_spot{currency}_{market}_trades"}'
print msg.format(**{'currency': 'usd', 'market': 'btc'})
我想格式化,但我得到一个错误。如何格式化字典的JSON
Traceback (most recent call last):
File "/Users/wyx/bitcoin_workspace/fibo/tests/t_ws.py", line 21, in <module>
print msg.format(**{'currency': 'usd', 'market': 'btc'})
KeyError: '"event"'
我什至不知道为什么我得到这个错误。
一个** **便宜的方法是使用'replace',即'msg.replace('{currency}','usd')。replace('{market}','btc')',它会起作用,但不是正确的做法。 – Bijoy
哪里'msg'来自? –