tzwhere(pytzwhere)Python2.7和简单的测试CA

2024-03-28 11:33:07 发布

您现在位置:Python中文网/ 问答频道 /正文

我在运行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

编辑:

根据以下注释,通过以下代码修改解决了此问题-

^{pr2}$

Tags: 模块in文档import选项错误gpsmodule
1条回答
网友
1楼 · 发布于 2024-03-28 11:33:07

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

from tzwhere import tzwhere w = tzwhere()

第一行从模块导入tzwhere。在

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

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

我想你是想用https://github.com/pegler/pytzwhere/blob/master/tzwhere/tzwhere.py

相关问题 更多 >