标签: zope.interface

Zope接口的目的?

我已经开始在我的代码中使用Zope接口,截至目前,它们实际上只是文档.我使用它们来指定类应具有的属性,在适当的类中显式实现它们,并在我期望的位置显式检查它们.这很好,但我希望他们在可能的情况下做更多的事情,比如实际验证该类是否已经实现了接口,而不仅仅是验证我已经说过该类实现了接口.我已经阅读了几次zope wiki,但仍然看不到比我目前正在做的更多的接口使用.所以,我的问题是你还可以使用这些接口,以及如何使用它们.

python zope interface zope.interface

34
推荐指数
3
解决办法
1万
查看次数

我在哪里放置.egg(Python)?

我正在尝试为Python安装zope接口脚本.但是,我看到的唯一下载是.egg文件类型.我正在运行Windows Python 2.7,我应该把这个文件放在Zope接口上,以便与我的Python一起正常工作?

python egg zope.interface

5
推荐指数
1
解决办法
2825
查看次数

如何获取实现接口的类的列表?(zope.接口)

这个问题说明了一切。或者我试图用于zope.interface错误的目的?

我需要的基本上是注册实现特定功能的类(CMS 的小部件或 Portlet)的一种方法。基本上就像 django 对其 ModelAdmin 类所做的那样,但不是自动的,也不是魔法。

python zope interface zope.interface

5
推荐指数
1
解决办法
2212
查看次数

让py2exe与zope.interface一起使用

我有一个基于Twisted和PyGTK的Python应用程序.扭曲本身取决于zope.interface,我不直接导入它.

不幸的是,当我尝试运行我的应用程序时,错误日志中会出现以下错误:

Traceback (most recent call last):
  File "tasks.py", line 4, in <module>
  File "ui\__init__.pyc", line 14, in <module>
  File "twisted\python\log.pyc", line 17, in <module>
ImportError: No module named zope.interface
Traceback (most recent call last):
  File "tasks.py", line 4, in <module>
  File "ui\__init__.pyc", line 14, in <module>
  File "twisted\python\log.pyc", line 17, in <module>
ImportError: No module named zope.interface
Traceback (most recent call last):
  File "tasks.py", line 4, in <module>
  File "ui\__init__.pyc", line 14, in <module>
  File "twisted\python\log.pyc", line 17, in …
Run Code Online (Sandbox Code Playgroud)

python pygtk twisted py2exe zope.interface

5
推荐指数
2
解决办法
8943
查看次数

python中的zope.interface.registry中的导入错误

我正在虚拟环境中安装项目。我遇到错误

from zope.interface.registry import Components
Traceback (most recent call last):
  File "<console>", line 1, in <module>
ImportError: No module named registry
Run Code Online (Sandbox Code Playgroud)

该模块的版本为4.0.5

>>> import pkg_resources
>>> pkg_resources.get_distribution("zope.interface").version
'4.0.5'
Run Code Online (Sandbox Code Playgroud)

我在机器上尝试了相同的操作(不是虚拟环境),

>>> import pkg_resources
>>> pkg_resources.get_distribution("zope.interface").version
'4.0.1'
>>> from zope.interface.registry import Components
Run Code Online (Sandbox Code Playgroud)

这里from zope.interface.registry import Components没有给出任何错误。根据这个

QUOTE: 3.8.0 (2011-09-22) 
New module zope.interface.registry. This is code moved from 
zope.component.registry which implements a basic nonperistent component registry 
as zope.interface.registry.Components.
Run Code Online (Sandbox Code Playgroud)

,它不应出现任何错误。有什么建议我在这里缺少什么或如何解决这个错误?

python importerror zope.interface

5
推荐指数
1
解决办法
1858
查看次数

如何动态地向接口添加属性

我需要为接口中的每个属性添加一个属性.所以我试图动态修改它来添加它们,但现在还没有取得多大成功.

假设我有以下界面:

class IMember(Interface):
    first_name = schema.TextLine(title=u'first name')
    last_name = schema.TextLine(title=u'last name')
Run Code Online (Sandbox Code Playgroud)

我想像这样修改它:

class IMember(Interface):
    first_name = schema.TextLine(title=u'first name')
    last_name = schema.TextLine(title=u'last name')
    visbility_first_name = schema.Bool(title=u'Display: first name')
    visbility_last_name = schema.Bool(title=u'Display: last name')
Run Code Online (Sandbox Code Playgroud)

我之后尝试修改了类,但由于它已经初始化,因此设置了架构,我不知道如何更改它.我还想过编写一个指令(例如:interface.Implements())但是添加属性似乎很复杂.

我的最终目标是添加一个带有一组Bool小部件的z3c.form字段集.

那么,有没有办法在Python中完成它,或者我是否必须修改界面并手动添加所有属性?

谢谢 !

python plone zope.interface

4
推荐指数
1
解决办法
348
查看次数

如何在类声明中调用函数?

有这个代码:

>>> class Foo:
...     zope.interface.implements(IFoo)
...
...     def __init__(self, x=None):
...         self.x = x
...
...     def bar(self, q, r=None):
...         return q, r, self.x
...
...     def __repr__(self):
...         return "Foo(%s)" % self.x
Run Code Online (Sandbox Code Playgroud)

Obviously, the call of zope.interface.implements in some way alters the properties and behavior of the class Foo.

How does this happen? How do I use this approach in my code?

Example code is the part of zope.interface module.

python zope metaprogramming zope.interface

3
推荐指数
1
解决办法
644
查看次数

导入错误:没有名为“zope.interface”的模块

在苹果机上:

Traceback (most recent call last):
  File "project1/scripts/initializedb.py", line 3, in <module>
    import transaction
  File "/Users/denmojo/code/project1/env/lib/python3.5/site-packages/transaction/__init__.py", line 19, in <module>
    from transaction._transaction import Transaction
  File "/Users/denmojocode/project1/env/lib/python3.5/site-packages/transaction/_transaction.py", line 20, in <module>
    from zope.interface import implementer
ImportError: No module named 'zope.interface'
Run Code Online (Sandbox Code Playgroud)

无法弄清楚为什么它在那里,但没有导入模块。

Using /Users/denmojo/code/project1/env/lib/python3.5/site-packages/zope.interface-4.3.2-py3.5-macosx-10.6-intel.egg
Run Code Online (Sandbox Code Playgroud)

transactions pip pyramid zope.interface python-3.5

1
推荐指数
1
解决办法
3576
查看次数