[Zope] Tricky (I think!) external method question...

Andy McKay andym@ActiveState.com
Tue, 30 Oct 2001 11:35:59 -0800


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 )
>