[Tutor] Function output

David Porter jcm@bigskytel.com
Sun, 25 Jun 2000 04:23:08 -0600

* william <wmperry@903internet.com>:

> The problem I'm having is how to get output from the functions in a module
> to the screen. I wanted to try writing something other than the book
> exercises to get a better feel for the process, I wrote a function that
> generated a random number and a second function that used that number to
> select from a list. When I type them in in the interactive prompt in Idle
> they do exactly that but when I place them in a module and save. They
> refuse to output to the screen either in Idle or from the DOS prompt. I've
> been working at this for several weeks and the error message(s) change
> depending on what I try, including no error message and no output. I added
> a test print message at the end and it does print so It appears to be that
> the function output isn't being captured or read.  

> I'm less concerned with making this work than in why it won't and where I
> should be looking to find answers.

From what I understand it works like this. In your function, if you use
'return', then it returns a value (if you don't, it returns a value too:
'None'). While at the python prompt, these are displayed, but you must use
'print function()' in your scripts if you want the user to see the output. I
assume that they are displayed at the prompt because that is informative for
the programmer. Imagine though how bad it would be if all of your functions
printed out something to the user of your program even when you hadn't
explicitly requested it!