[Zope] RE: Importing Products into my Custom Product....
Paul Winkler
pw_lists at slinkp.com
Sat Sep 11 15:57:50 EDT 2004
On Sat, Sep 11, 2004 at 11:52:16AM -0700, Bill Hewitt wrote:
> I am asking this question again in hopes that maybe this time it will
> make more sense....
>
> What I want to do is reuse code from one product to the next in a Python
> Class...... This is trivial in a ZClass, but ????
>
> Anyway, I create a new Python Product "FOO" and I want to import the
> methods of another Python Product "Bar" ("FOO" and "BAR" are next to
> each other in the Products Directory), so I add
> "import Bar" into my __init__.py file for "FO0"
Two points here:
1) You're mixing different capitalization styles. You might
get away with that on Windows but it will bite you
on any case-sensitive platform...
2) You don't need to import Bar in Foo's __init__.py,
you should instead put your imports in whatever module
of Foo actually needs to call methods from Bar. See below for
how to do this.
> When I do this, the ZServer complains that the module does not
> exist..... So, I try:
> "from Bar import Bar" and "from Bar.Bar import Bar" and "from
> Products.Bar import Bar"
The latter should work, so something must be wrong.
Here's a working example of the CMFDefault product importing
something from the CMFCore product:
from Products.CMFCore.CMFCorePermissions import View
This works because the following conditions are satisfied:
1) CMFCore is a proper package: i.e. it must
have an __init__.py file.
2) CMFCore is placed in the Products directory.
3) CMFCore/CMFCorePermissions.py must exist.
4) CMFCorePermissions.py must have a module-level
name View.
--
Paul Winkler
http://www.slinkp.com
More information about the Zope
mailing list