小编loc*_*ocq的帖子

在 json 数据列表中使用 python f-string

我需要通过他们的 API 将数据推送到网站,并且我正在尝试找到一种使用 F 字符串传递数据列表中的变量的方法,但找不到方法。

到目前为止,这是我尝试过的:

today = datetime.date.today()
tomorrow = today + datetime.timedelta(days = 1)

#trying to pass *tomorrow* value with f-string below

data = f'[{"date": "{tomorrow}", "price": {"amount": 15100}}]'

response = requests.put('https://api.platform.io/calendar/28528204', headers=headers, data=data)
Run Code Online (Sandbox Code Playgroud)

我怎样才能实现这个目标?

python json list f-string

7
推荐指数
1
解决办法
2万
查看次数

标签 统计

f-string ×1

json ×1

list ×1

python ×1