【问题标题】:Overriding a constant in a module覆盖模块中的常量
【发布时间】:2015-07-01 03:47:18
【问题描述】:

我正在使用 Python Pygatt 模块 (https://github.com/ampledata/pygatt/tree/master/pygatt)。

classes.py 文件导入 pygatt.constants,它设置了一些常量。我无法弄清楚如何在我尝试过的文件 foo.py 中覆盖这些常量:

import pygatt

pygat.classes.pygatt.constants.DEFAULT_CONNECT_TIMEOUT_S = 8

但它不起作用。我很困惑,这可能是我正在做的愚蠢的事情。我们将不胜感激!

【问题讨论】:

标签: python constants


【解决方案1】:

试试这个:

from pygatt.classes import pygatt
pygatt.constants.DEFAULT_CONNECT_TIMEOUT_S = 8

【讨论】:

  • 当你说它不起作用时,你是什么意思?它是抛出错误还是只是没有在运行时获取更改?
  • 另请注意,您在示例中有一个错字,第一个“pygat”缺少一个“t”
猜你喜欢
  • 2012-09-11
  • 2022-01-24
  • 1970-01-01
  • 2021-05-04
  • 1970-01-01
  • 1970-01-01
  • 2023-01-28
  • 1970-01-01
  • 2014-01-29
相关资源
最近更新 更多