[ALUG] Python question about classes

Richard Lewis richardlewis at fastmail.co.uk
Mon Jun 11 10:51:07 BST 2007


On Monday 11 June 2007 10:26:35 Chris G wrote:
> #
> def cb_prepare(args):
>     request = args["request"]
>     data = request.getData()
>     data["statcatslinks"] = PyblStatcats(request)
>
>
> What I'm not clear about is the last line, PyblStatcats is a class.
> As I understand it 'PyblStatcats(request)' creates an instance of
> PyblStatcats and runs its __init__ method, so far so good.  But what
> does 'PyblStatcats(request)' return?  It would appear to be a string
> as it's used to set the value in the data dictionary.  However I can't
> find anywhere in the Python documentation that tells me about this
> (implicit?) return value.

If PyblStatcats is a class, then calling it must return an instance of 
PyblStatcats. If you include a return statement in a class's __init__ method, 
it can only return None, anything else raises an exception.

Are you sure that this call is returning a string? Might it be returning an 
object which has an explicit __str__ method? What does

py> data["statcatslinks"].__class__

say?

Cheers,
Richard
-- 
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Richard Lewis
http://www.richard-lewis.me.uk/
JID: ironchicken at jabber.earth.li
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-



More information about the main mailing list