简体   繁体   English

文档中的zope.annotation示例失败。 需要帮助来纠正它

[英]zope.annotation example in documentation fails. Help needed to correct it

I am trying to understand Annotations from this document: 我试图从此文档中了解注释:

http://docs.zope.org/zope.annotation/index.html http://docs.zope.org/zope.annotation/index.html

However the example fails when run. 但是,该示例在运行时失败。

I get: 我得到:

Traceback (most recent call last):
  File "./zopepy", line 366, in <module>
    exec(compile(__file__f.read(), __file__, "exec"))
  File "test1.py", line 29, in <module>
    bar = IBar(foo)
  File "eggs/zope.component-3.9.5-py2.7.egg/zope/component/_api.py", line 156, in adapter_hook
    return sitemanager.queryAdapter(object, interface, name, default)
  File "eggs/zope.component-3.9.5-    py2.7.egg/zope/component/registry.py", line 228, in queryAdapter
    return self.adapters.queryAdapter(object, interface, name, default)
  File "eggs/zope.annotation-3.5.0-py2.7.egg/zope/annotation/factory.py", line 42, in getAnnotation
    annotations = zope.annotation.interfaces.IAnnotations(context)
TypeError: ('Could not adapt', <__main__.Foo object at 0xb6d6956c>,    <InterfaceClass zope.annotation.interfaces.IAnnotations>)

Example missing the following statements: 示例缺少以下语句:

from zope.annotation.attribute import AttributeAnnotations
provideAdapter(AttributeAnnotations)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM