【问题标题】:Python : Getting "OverflowError: repeated string is too long" when creating dictionaryPython:创建字典时出现“溢出错误:重复的字符串太长”
【发布时间】:2019-07-02 15:17:49
【问题描述】:

我正在尝试转换这行代码:

array_of_power1.append(dict(measurement=topic_mqtt_power1,timestamp=int(epoch_time_stamp * 1000000000),fields=dict(power=power1),tags=dict(MachineType=Machine_type,MachineName=Machine_name)))

进入

array_of_power1.append({'measurement' : 'topic_mqtt_power1', 'timestamp' : 'epoch_time_stamp' * 1000000000, fields: {'power' : 'power1'}, tags: {MachineType : Machinetype, MachineName : Machine_name}})

我得到了

Traceback(最近一次调用最后一次):文件“”,第 1 行,in OverflowError: 重复字符串太长

我从 dict 结构更改为另一种方法的原因是 dict 结构“dict()”在 micropython 中不起作用。

【问题讨论】:

  • 通过写'epoch_time_stamp' * 1000000000 你正在写epoch_time_stamp 1000000000时间,删除*
  • 现在有意义了,谢谢!我遇到的第二个问题是它显示“NameError: name 'fields' is not defined”?

标签: python dictionary micropython


【解决方案1】:

你应该运行这样的东西来避免 OverflowErrorNameError 的错误:

array_of_power1.append({'measurement' : 'topic_mqtt_power1', 
                        'timestamp' : 'epoch_time_stamp x 1000000000',
                        'fields': {'power' : 'power1'}, 
                        'tags': {MachineType : Machinetype, MachineName : Machine_name}})

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-02-01
    • 2013-02-09
    • 2011-09-05
    • 1970-01-01
    • 2022-11-15
    • 2012-06-17
    • 1970-01-01
    相关资源
    最近更新 更多