A question on how external methods reference modules
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. 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. 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? As a second part of the question, will this allow me to modify the external modules without re-loading them into Zope? 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@bar-s.com.
On 12/6/03 2:13 PM, "Goldthwaite, Joe" <invalid@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@bar-s.com.
These types of sigs are SO annoying on a public mailing list... -k
Thanks Kapil. That explanation helps.
These types of sigs are SO annoying on a public mailing list...
It's annoying to me to!!! The company where I spend most of my time started putting it on all emails going out from their firewall. I signed up for an external mail service to try and get around it only to find that they're doing at a the protocol level not at the mail server so it was still getting tacked on. I had to subscribe to a mail service that supports SSL connections. Now I connect to my mail server through an encrypted tunnel so the firewall can't touch it. I actually have to pay to get that damn thing off my emails! Unfortunately, it sometimes screws up. If Outlook can't connect to my mail server, it trys the company one. Something like that happened this time and that's why the email got posted twice. Sorry about that. Joe Goldthwaite
Goldthwaite, Joe wrote: ...
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?
Running the external method that calls 'module1.ReturnData' isn't like running it from regular Python. There's (I believe) some Zope context involved. I suspect that you could import your second module if it were in a product and you imported it from 'Products.TheProduct.Extensions.module2' and Extensions had an __init__.py. But really, isn't it easier to make GetTheData also an external method and use it as a Zope method? --jcc -- "My point and period will be throughly wrought, Or well or ill, as this day's battle's fought."
participants (4)
-
Goldthwaite, Joe -
Goldthwaite, Joe -
J. Cameron Cooper -
kapil thangavelu