possibly a dumb question

Adonis deltapigz at telocity.com
Sat Jun 29 21:44:00 EDT 2002


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.


"Peter Hansen" <peter at engcorp.com> wrote in message
news:3D1E6415.8128F3F8 at engcorp.com...
> Adonis wrote:
> >
> > can a class return a value? i have treid to google this, but have found
> > myself short of an answer, i know i could place it in a member and
> > it or through a function, but im trying to simplify my life.. just a
> > little..
> You probably don't actually mean a class.  I think you mean an object,
> which is an instance of a class.  (If I've got that wrong, I think
> we need clarification of the question.)
> If that's the case, there's still one more problem left. :-)
> "Returning a value" is a concept related to calling a method
> or function.  It doesn't have any particular meaning if you
> ask "can an object return a value?" unless you mean something
> like "can a method of an object return a value?".  That is
> certainly possible, although I'm not this is what you wanted,
> either:
> >>> class MyClass:
> ...    def myMethod(self):
> ...        return 'spam'
> ...
> >>> c = MyClass()
> >>> print 'Green eggs and %s.' % c.myMethod()
> Green eggs and spam.
> Can you ask the question in a different way, or show an example
> of what you were hoping to do?
> -Peter

More information about the Python-list mailing list