[Tutor] returning from a function?

Suzanne Little s349929@student.uq.edu.au
Sat, 17 Mar 2001 18:45:24 +1000 (GMT+1000)


Sorry but I don't have access to the snipped part at the moment. It
doesn't contain any return statements or print statements. All output
comes from the final case which is the code listed. In general terms the
snipped section takes the first string from the list and finds it within
the child nodes of the base node and then calls accessData again with the
new base node and the string removed from the list. It's a little more
complicated than that to cope with potential doubles and selecting between
them based on a supplied attribute value (eg: 'id=3'). Hopefully that
makes it clear enough.

Thanks,
Suzanne


On Fri, 16 Mar 2001, Michael P. Reilly wrote:

> > Hi,
> >
> > It was difficult to think of a subject line for this because I don't know
> > what's going on. I have a function, listed below, but it returns None
> > instead of what I think it should - which is a unicode string. The
> > function is intended to be part of a class which will search an xml file
> > for text from the location specified and I want it to return either a list
> > of nodes or the value of the node. I've tried returning various things,
> > strings, node objects, but everything is None.
> >
> > Some code and a sample run follows
> > ------------------------
> > from string import *
> > from xml.dom.minidom import parse
> > import xml.dom
> >
> > def accessData(baseNode, accessList):  #recursive function
> >     if len(accessList) == 0:
> >         print baseNode  #for debug
> >         print baseNode.firstChild  #for debug
> >         res = baseNode.firstChild.data
> >         print res, type(res)  #for debug
> >         return res
> >     else:
> > 	#Recursion code <snipped>
>
> The key part may be what you snipped.  Is this part returning the
> result of the deeper recursion of accesData?  For example, are you
> doing something like "return accessData(baseNode, accessList[1:])"?
>
>   -Arcege
>
> --
> ------------------------------------------------------------------------
> | Michael P. Reilly, Release Manager  | Email: arcege@shore.net        |
> | Salem, Mass. USA  01970             |                                |
> ------------------------------------------------------------------------
>
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
>

--------------------------------------------------------------------------
"Contrariwise," continued Tweedledee, "If it was so, it might be; and if
it were so, it would be; but as it isn't, it ain't.  That's logic"
                             -Lewis Carroll
--------------------------------------------------------------------------