python - tzwhere (pytzwhere) - Python 2.7 和简单的测试用例

标签 python ipython pytz

我正在运行 pytzwhere 包提供的最简单的测试问题。模块导入,但我收到错误。 pytzwhere 似乎是从 GPS 坐标获取时区的一个不错的离线选项,但没有太多文档。任何有关如何协调这一点的帮助都将受到赞赏!

In [94]:

import tzwhere

w = tzwhere()
print w.tzNameAt(1.352083, 103.819836)
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-94-0b50c8083e93> in <module>()
      1 import tzwhere
      2 
----> 3 w = tzwhere()
      4 print w.tzNameAt(1.352083, 103.819836)

TypeError: 'module' object is not callable

编辑:

已根据下面的评论通过以下代码修改解决了此问题 -

In [108]:

from tzwhere import tzwhere

w = tzwhere.tzwhere()
print w.tzNameAt(1.352083, 103.819836)
-----------------------------------------------------------------------------
Reading json input file: /Users/user/anaconda/lib/python2.7/site-packages/tzwhere/tz_world_compact.json
Asia/Singapore

最佳答案

您不能像 w = tzwhere() 这样从模块中实例化 w。 tzwhere 是一个包含 tzwhere 类的模块。正如 Python 正确指出的那样,模块不可调用。

从 tzwhere 导入 tzwhere w = tzwhere()

第一行从模块 tzwhere 导入class tzwhere。

编辑:如果您确实导入“我的方式”:-) w = tzwhere() 是 w 作为 class tzwhere 实例的有效创建。

通常在 Python 中,类将被命名为 TzWhere,这样可以避免这种混淆。

我假设您正在尝试使用 https://github.com/pegler/pytzwhere/blob/master/tzwhere/tzwhere.py

关于python - tzwhere (pytzwhere) - Python 2.7 和简单的测试用例,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23769883/

相关文章:

python - Pandas :绘制唯一值图

python - 在列表中找不到术语,ValueError : list. 索引(x):x 不在列表中

python - Pandas `str.extract()` 中带有捕获组的正则表达式的预期行为

python - Jupyter(IPython)笔记本不绘图

python - 使用 Py2Exe 编译的 Python 应用程序引发 UnknownTimezoneError 异常

python - pytz:仅从 GMT 偏移返回 Olson 时区名称

python - 如何将嵌套字典变成平面字典并用重复键对值求和?

python - 如何从脚本运行 IPython 魔术(或为 Python 脚本计时)

python - 如何让 IPython Notebook 运行 Python 3?

python & pytz : Figure out if a timezone supports DST and what the DST and non-DST UTC offsets are