1

这真的很奇怪。如果我运行这段代码(作为鼻子测试),它会打印“-0:34:00.0”,一切都很好

def test_o1(self):
    observer = ephem.Observer()
    observer.lon, observer.lat = math.radians(73.9), math.radians(40.7)
    observer.horizon = '-0:34'
    print observer.horizon

但是,如果我运行这个:

def test_o2(self):
    location = UserLocation()
    location.foo()

其中用户位置是:

# Document is mongoengine.Document
class UserLocation(Document):
    [...]
    def foo(self):
        observer = ephem.Observer()
        observer.lon, observer.lat = math.radians(73.9), math.radians(40.7)
        observer.horizon = '-0:34'

我得到:

Traceback (most recent call last):
  File "/home/roy/deploy/current/python/local/lib/python2.7/site-packages/nose/case.py", line 197, in runTest
    self.test(*self.arg)
  File "/home/roy/deploy/current/code/pyza/models/test_user_location.py", line 82, in test_o2
   location.foo()
  File "/home/roy/deploy/current/code/pyza/models/user_location.py", line 134, in foo
    observer.horizon = '-0:34'
TypeError: can only update value with String or number

知道会发生什么吗?

4

1 回答 1

1

啊啊啊。我想到了。我的 UserLocation 源文件以:

未来导入 unicode_literals

显然,_libastro 坚持使用 ascii 字符串,而不是 unicode。

于 2014-02-25T22:07:23.463 回答