首页 > 解决方案 > 从 .json 文件中获取数据时,“元组”对象没有“格式”属性

问题描述

(使用python 2.7)

mySettings 是一个 .json 文件

我一直在使用 Streamlabs 为 twitch 开发聊天机器人脚本,如果开发人员将设置格式化为 .json 文件中的设置,他们有一个系统允许流媒体编辑设置:

},
"AcceptVipResponse": {
  "type": "textbox",
  "value": "Congratulations {0} you are now VIP!",
  "label": "When a user sucesfully purchases VIP",
  "tooltip": "Message sent when the bot succesffully gives them VIP role \r\n {0} = user",
  "group": "Responses"
},

这几乎适用于我的所有代码,例如:

Parent.SendStreamMessage(mySettings.AcceptVipResponse.format(data.GetParam(1))) 

'Parent.SendStreamMessage' 向流的聊天发送消息,'data.GetParam(1)' 只是聊天者用户名的字符串

但是,当它运行代码行时:

Parent.SendStreamMessage(mySettings.NotEnoughResponse.format(data.UserName,Parent.GetCurrencyName, str(cost)))

我收到一条错误消息:

“元组”对象没有属性“格式”

这所指的 .json 文件的部分是:

},
"NotEnoughResponse": {
  "type": "textbox",
  "value": "{0} you don't have enough {1} to purchase vip it costs {2}",
  "label": "Not enough currency response",
  "tooltip": "Message sent when user try to tombola more than they have \r\n {0} = user \r\n {1} = Currency name \r\n {2} = Cost",
  "group": "Responses"
},

我不知道为什么 python 将一个称为元组,但其他的完全没问题,任何帮助将不胜感激。

标签: pythonpython-2.7

解决方案


推荐阅读