我編寫了這行代碼來格式化消息,但它給了我這個錯誤:Traceback (most recent call last): File "yes.py", line 221, in buy_stock message = f'{"action": "Bought {amount} stocks", "current-money": "{self.money}", "money-combined": "{self.money_combined}", "stocks" : "{self.stock_amount}"}'ValueError: Invalid format specifierpython3.8編寫,所有變量均已定義。我試圖以 json 格式制作此消息,以便我可以將其發送到服務器,服務器對數據進行一些信息收集。
1 回答

千萬里不及你
TA貢獻1784條經驗 獲得超9個贊
再用一對大括號括起來,如下所示
message = f'{{"action": "Bought {amount} stocks", "current-money": "{self.money}", "money-combined": "{self.money_combined}", "stocks" : "{self.stock_amount}"}}'
添加回答
舉報
0/150
提交
取消