[Zope] A question on how external methods reference modules

kapil thangavelu hazmat at objectrealms.net
Sun Dec 7 05:21:02 EST 2003


On 12/6/03 2:13 PM, "Goldthwaite, Joe" <invalid at bar-s.com> wrote:

> I've gotten my external module working but It has one little hassle I've been
> trying to get around.  If I make a change to the module, I have to go back to
> the management screen -> External method name and click on the Save Changes
> button.  

use zope in debug mode and this is automatic at the expense of some speed.

>It looks like this brings the changes into Zope.  Well, I had the
> bright idea of linking to a stub function that doesn't change and then have
> the stub function call the real function that's imported.  I figured I could
> then modify my method without re-loading it into Zope.

this won't work. the second module will be imported and cached until
restart. python automatically caches imports of modules.

> 
> I basically created two modules. In module1.py I have my stub function that
> chains to module2.py.
> 
> module1.py
> 
>  import module2
> 
>  def ReturnData():
>     """Return some test data"""
>     return module2.GetTheData()
> 
> module2.py
> 
>  def GetTheData():
>     """Return the actual data"""
>     return """the actual data"""
> 
> I can run this in python and it works.  After the import module2, I can do a
> dir on the module2 namespace and I see "GetTheData" as one of the items in the
> list.  When I add module1->ReturnData to the external module in Zope and
> execute it, I get the error "module 'mytest' module has no attribute
> 'GetTheData'".
> If I modify ReturnData to this;
> 
>  import module2
>  def ReturnData():
> """Return some test data"""
>     return dir(module2)
> 
> the string returned does not show my "GetTheData" function in the list.  I was
> getting an error that 'module2' wasn't found so I had to append it's path
> using the sys.path.append function.  Now I'm not getting an error so I think
> it's finding module2 but it doesn't seem to be finding the function.  I'm
> confused.  Can anyone explain what's going on?

I'm a little hazy on this stuff... but diving in anyways..

external methods don't operate as python modules in the normal sense, in
that their execution context is different, such that the other modules you
might have in your Extensions directory are not directly importable without
giving a full python path for import them. which also means you would need
to turn your Extensions directory into a package with an __init__.py file

> 
> As a second part of the question, will this allow me to modify the external
> modules without re-loading them into Zope?

no, see the first part of my response for a solution.

> Property of Bar-S Foods. This message is intended only for the use of the
> Addressee and may contain information that is PRIVILEGED and CONFIDENTIAL.  If
> you are not the intended recipient, dissemination of this communication is
> prohibited.  If you have received this communication in error, please erase
> all copies of the message and its attachments and notify us immediately at
> 602.264.7272 or postmaster at bar-s.com.
> 

These types of sigs are SO annoying on a public mailing list...

-k




More information about the Zope mailing list