[Tutor] return, why do I need it?

Wayne Werner waynejwerner at gmail.com
Sun Dec 11 19:45:13 CET 2011


On Dec 11, 2011 8:41 AM, "Pete O&apos;Connell" <pedrooconnell at gmail.com>
wrote:
>
> Hi I have been writing python code for a while now and I never return
anything within any of my functions, I just (eg.) print stuff or make
directories or update a log or what have you. When I look at other people's
code they are always returning in their functions and I was wondering if
someone could give me an example of when I would absolutely have to return
something. The thing I don't like about returning is that when I unindent a
function and try to run the code to inspect parts of it for debugging I
always have to alter the code so as not to get the "return not inside a
function error",  so I will change the word "return" to "print" and in many
cases that's the way I leave it. Anyone have any thoughts on this?
>

No one has mentioned it so far, but the interactive interpreter is what you
should use for debugging short code snippets.  I always program with two
windows open - one with my editor and one with the interpreter. This lets
me try out short bits of code without running my whole program.

Hth,
Wayne
> Thanks
> Pete
>
>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20111211/fa74fc09/attachment.html>


More information about the Tutor mailing list