converting object ref to value????

Peter Otten __peter__ at web.de
Sun Oct 19 05:21:19 EDT 2003


Ken Godee wrote:

> I'm confused, I have a class returning a value from
> a method of that class and I'm getting a reference
> to the object instead of the actual returned value.
> How can I convert it back to an actual value I can use for
> further processing?
> 
> ie.
> 
> import manager
> 
> a = manager.Manager()
> 
> xx = a.connect()
> 
> print xx
> 
> <manager.Manager object at 0x81d7034>

Seems like the connect() method has no meaningful return value, e. g. a
manager.Connection object, so it returns self to allow you to write

a.connect().doSomething(someData)

instead of

a.connect()
a.doSomething(someData)

To be sure, you can add the test:

if xx is a:
    print "connect() method returns self"

Of course, to explore what the actual methods of the Manager object instead
of the speculative doSomething() are, you have to consult the manager
module's documentation.

HTH,
Peter




More information about the Python-list mailing list