格式字符串dict
我想定义带有变量的有效载荷,有效载荷包含一个dict dict的dict,这样的有效载荷:
payload = {"columns": "{x,y,z}",
"number": "{n:123456}"}
我希望理想地对变量类似:
myVar = 123
payload = {"columns": "{x,y,z}",
"number": "{n:{myVar}}"}
但是,这种和其他组合不起作用。我已经尝试了F-strings和Formats。最好的方法是什么?
I want to have define a payload with variables, and the payload contains a dict inside a dict, like so:
payload = {"columns": "{x,y,z}",
"number": "{n:123456}"}
I wanted ideally something like for a variable:
myVar = 123
payload = {"columns": "{x,y,z}",
"number": "{n:{myVar}}"}
However this and other combinations doesn't work. I've tried both f-strings and formats. What is the best approach for this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以做:
或:
或:
所有印刷品:
You can do:
Or:
Or:
All prints: