[Zope] A question on how external methods reference modules
J. Cameron Cooper
jccooper at jcameroncooper.com
Mon Dec 8 22:40:33 EST 2003
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."
More information about the Zope
mailing list