我在运行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}$
不能像
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
相关问题 更多 >
编程相关推荐