possibly a dumb question

Peter Hansen peter at engcorp.com
Sat Jun 29 22:30:27 EDT 2002


Adonis wrote:
> 
> sure:
> 
> class foo:
>     def __init__(self, value):
>         return value
> x = foo(0)
> print x ;yeilds 0
> 
> i know the code provided is wrong, but its the general idea.

Ahh, you simply cannot do that.  The __init__() method is
defined to return a reference to the object which it initializes
and you can't change that.  Note the error message given:

  TypeError: __init__() should return None

Anyway, you really don't need to do this, since in your other
post you give your goal (sort of).  I'll paste the message here:

"""an addition:
   why not use a function blah blah, yes, but this is going to be 
   a modularized project, essentially i want to load some user made 
   modules which will be classes and will be loaded into python 
   dynamically. like a memory resident cgi server skipping the use of 
   pipes."""

Okay, trying again:  The above is still not quite correct, because
"modules which will be classes" is wrong.  I guess you mean the modules
will contain class definitions?  In that case, you still need to 
create instances of the classes (like the "x = foo()" part above)
and then call methods of the classes.

Can you clarify further?  What you're trying to accomplish is not
hard (I believe... once we figure out exactly what it is) but you
are starting off on the wrong foot.

-Peter



More information about the Python-list mailing list