return statement in functions

Jp Calderone exarkun at intarweb.us
Tue Dec 23 14:50:11 EST 2003


On Tue, Dec 23, 2003 at 02:05:25PM -0500, hokieghal99 wrote:
> Jp Calderone wrote:
> [snip]
> >
> >  No.  "return new_dname" terminates execution of the function.  If you
> >  want many results, you need to collect them in a list and return the
> >  list, or use a generator.
> >
> >  Jp
> 
> That's odd, it seems silly to terminate something that should be 
> recursive (os.walk) before it's finished being recursive. What's the 
> logic behind that idea?
> 

  That is what "return" does.  Always.  :)  With no regard for context,
recursive or not (the implementation of os.walk itself may be recursive, or
it may not be, but I don't think it has any bearing on what "return" should
do, since the return isn't even inside the definition of os.walk!)

  If this is surprising, you should probably take some time to review the
fundamentals of the language.  I would recommend either the official
tutorial or the book "How to Think Like a Computer Scientist":

    http://www.python.org/doc/tut/

    http://www.ibiblio.org/obp/thinkCSpy/

  Jp
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 196 bytes
Desc: Digital signature
URL: <http://mail.python.org/pipermail/python-list/attachments/20031223/0153b3b3/attachment.sig>


More information about the Python-list mailing list