[Zope] calling another products methods

J Cameron Cooper jccooper at jcameroncooper.com
Tue Dec 2 15:37:20 EST 2003


Terry Hancock wrote:

>On Tuesday 02 December 2003 12:59 pm, Dylan Reinhardt wrote:
>  
>
>>On Tue, 2003-12-02 at 10:32, Matthew Thorley wrote:
>>    
>>
>>>As the subject indicates I am working with a product(P1) and I would like to 
>>>call the methods of a different product(P2) from with in the first. When I 
>>>try from P@ import method I get an error. How do I get P2 to into the 
>>>namespace of P1 or at least into the global namespace. 
>>>      
>>>
>>Untested, obviously... but probably close enough to help:
>>
>>-----
>>from Products.P1.p1module import p1class
>>
>>def my_wrapper(self, request):
>>    return p1class.p1method(self, request)
>>-----
>>    
>>
>I can attest that this works.  I use it a *lot*, as I have a
>product with explicit dependencies on some other products.
>
>I also find that I need to import *my* product modules this
>way when I use nested directory/package structure in my
>product.  I have not found any equivalent to "../" in the way
>Python imports modules, so I can't just "go up a directory".
>
>Is there one, BTW?
>  
>
As I recall, this was explicitly rejected from Python for some reason. I 
suppose you can abstract it a bit by creating, say, a module 'parent' in 
your current package and importing the names present in the directory 
above: 'from Products.MyProduct import *'. Then you can 'from parent 
import SomeBasicClass'.

          --jcc

-- 
"Code generators follow the 80/20 rule. They solve most of the problems, but not all of the problems. There are always features and edge cases that will need hand-coding. Even if code generation could build 100 percent of the application, there will still be an endless supply of boring meetings about feature design."
(http://www.devx.com/java/editorial/15511)





More information about the Zope mailing list