Tricky (I think!) external method question...
Hi, I'm a relatively experienced python programmer who's just recently gotten into Zope. I've downloaded the pdf of 'The Zope Book' and looked through the various How-To's but I'm stuck on the following problem: Starting from the top.... I have a DTML Document which is essentially a simple data input form. The 'ACTION' attribute of the 'FORM' statement calls a python Script to clean up and format the data. As part of this, the Script calls a number of External Methods, all of which are written in python. I do this by using the 'container' binding (e.g. x = container.myExternalMethod()). Some of these External Methods in turn import various .py files from my personal python directory which is totally separate and apart from where Zope/Extensions lives in the filesystem. In general all this works -- I get the results I expect. My problem comes from the one External Method that imports a .py file that contains a subclassed Class. The External Method looks like this: import MySubClass def aFunction(self,a,b,c): d = MySubClass.MySubClass(a,b,c) return d MySubClass in turn looks like this: import MyClass class MySubClass(MyClass.MyClass): def __init__(self,a,b,c): """Do some initialization that differs from MyClass""" return d The External Method above dies when it tries to create 'd'. The traceback I get from Zope says: Error Type: TypeError Error Value: __init__() should return None I'm stumped by this. I think there is some sort of namespace confusion going on but I'm not sure. If anyone can shed any light on this (and save some of my hair!) I'd appreciate it. Thanks, Steve
On Tue, Oct 30, 2001 at 02:14:59PM -0500, Steven Sartorius wrote: (snip)
import MyClass class MySubClass(MyClass.MyClass): def __init__(self,a,b,c): """Do some initialization that differs from MyClass""" return d
That's your problem right there. This is not a Zope problem - python won't let you do that. You can't get a return value from __init__(). Try something similar at the python prompt: $ python Python 2.1.1 (#3, Oct 15 2001, 23:37:14) [GCC 2.96 20000731 (Red Hat Linux 7.0)] on linux2 Type "copyright", "credits" or "license" for more information.
class Foo: ... def __init__(self): ... return 1 ... c = Foo() Traceback (most recent call last): File "<stdin>", line 1, in ? TypeError: __init__() should return None
I tried it with python 1.5.2, same result. -- paul winkler home: http://www.slinkp.com music: http://www.reacharms.com calendars: http://www.calendargalaxy.com
The External Method above dies when it tries to create 'd'. The traceback I get from Zope says:
Error Type: TypeError Error Value: __init__() should return None
I'm stumped by this. I think there is some sort of namespace confusion going on but I'm not sure. If anyone can shed any light on this (and save some of my hair!) I'd appreciate it.
on 10/30/01 14:31, Paul Winkler at slinkp23@yahoo.com wrote:
On Tue, Oct 30, 2001 at 02:14:59PM -0500, Steven Sartorius wrote: (snip)
import MyClass class MySubClass(MyClass.MyClass): def __init__(self,a,b,c): """Do some initialization that differs from MyClass""" return d
That's your problem right there. This is not a Zope problem - python won't let you do that. You can't get a return value from __init__(). Try something similar at the python prompt:
$ python Python 2.1.1 (#3, Oct 15 2001, 23:37:14) [GCC 2.96 20000731 (Red Hat Linux 7.0)] on linux2 Type "copyright", "credits" or "license" for more information.
class Foo: ... def __init__(self): ... return 1 ... c = Foo() Traceback (most recent call last): File "<stdin>", line 1, in ? TypeError: __init__() should return None
I tried it with python 1.5.2, same result.
Do I feel like a maroon.... I had pulled that return out of the code but found I was still getting the same error. Guess I forgot to restart Zope and update the changed method. When I restarted Zope from the Control Panel things worked as expected. Thanks, Steve
On Tue, 2001-10-30 at 14:14, Steven Sartorius wrote:
Hi,
file that contains a subclassed Class. The External Method looks like this:
import MySubClass def aFunction(self,a,b,c): d = MySubClass.MySubClass(a,b,c) return d
MySubClass in turn looks like this:
import MyClass class MySubClass(MyClass.MyClass): def __init__(self,a,b,c): """Do some initialization that differs from MyClass""" return d
The External Method above dies when it tries to create 'd'. The traceback I get from Zope says:
Error Type: TypeError Error Value: __init__() should return None
there's an error in MySubClass's __init__ method; you cannot return anything other than a None from __init__ -- Tom Jenkins Development InfoStructure http://www.devis.com
This is a python error __init__ should always return None.
class a: ... def __init__(self): ... return 1 ... a() Traceback (most recent call last): File "<stdin>", line 1, in ? TypeError: __init__() should return None
Cheers. -- Andy McKay. ----- Original Message ----- From: "Steven Sartorius" <ssartor@bellatlantic.net> To: <zope@zope.org> Sent: Tuesday, October 30, 2001 11:14 AM Subject: [Zope] Tricky (I think!) external method question...
Hi,
I'm a relatively experienced python programmer who's just recently gotten into Zope. I've downloaded the pdf of 'The Zope Book' and looked through the various How-To's but I'm stuck on the following problem:
Starting from the top....
I have a DTML Document which is essentially a simple data input form. The 'ACTION' attribute of the 'FORM' statement calls a python Script to clean up and format the data. As part of this, the Script calls a number of External Methods, all of which are written in python. I do this by using the 'container' binding (e.g. x = container.myExternalMethod()). Some of these External Methods in turn import various .py files from my personal python directory which is totally separate and apart from where Zope/Extensions lives in the filesystem. In general all this works -- I get the results I expect. My problem comes from the one External Method that imports a .py file that contains a subclassed Class. The External Method looks like this:
import MySubClass def aFunction(self,a,b,c): d = MySubClass.MySubClass(a,b,c) return d
MySubClass in turn looks like this:
import MyClass class MySubClass(MyClass.MyClass): def __init__(self,a,b,c): """Do some initialization that differs from MyClass""" return d
The External Method above dies when it tries to create 'd'. The traceback I get from Zope says:
Error Type: TypeError Error Value: __init__() should return None
I'm stumped by this. I think there is some sort of namespace confusion going on but I'm not sure. If anyone can shed any light on this (and save some of my hair!) I'd appreciate it.
Thanks,
Steve
_______________________________________________ Zope maillist - Zope@zope.org http://lists.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope-dev )
participants (4)
-
Andy McKay -
Paul Winkler -
Steven Sartorius -
Tom Jenkins