execute script from within python3 interpreter and show interpreter results
Question: I am working inside the python 3 interpreter, and I want to use it for
homework.

first, I have a library called `mylibrary.py` like this

    
    
    from math import pi
    def area_circle(r):
       return(r*r*pi))
    

Second, I have a script called `homework.py` like this

    
    
    from mylibrary import *
    area_circle(3)
    area_circle(5)
    area_circle(3) + area_circle(5)
    

Now, I want to enter the python interpreter and somehow execute the script
`homework.py` as if I had typed these lines directly into the interpreter, and
I want the results to appear on the screen as the interpreter normally
displays them.

from the BASH prompt:

    
    
    $python3
    
    Python 3.4.3 (default, Oct 14 2015, 20:28:29) 
    [GCC 4.8.4] on linux
    Type "help", "copyright", "credits" or "license" for more information.
    
    >>> exec "homework"
    

Is there such a command? I want it to read my script and enter the lines into
the interpreter, so that what appears on the screen next is:

    
    
    >>> from mylibrary import * 
    >>> area_circle(3)
    28.274333882308138
    >>> area_circle(5)
    78.53981633974483
    >>> area_circle(3) + area_circle(5)
    106.81415022205297
    

Please note that I do not have `Idle`, i do not have `iPython`, I just have
the interpreter which I access from the BASH prompt.

I know that I could replace the functions in the library to explicitly call
the print function, something like this:

    
    
    def area_circle(r):
       a=r*r*pi
       print(a)
       return()
    

But I don't want that, as it would prevent me from using this function as a
building block of future functions.  
So I guess what I'm asking is how to execute the `homework` script line by
line into the interpreter, in the simplest way possible.


Answer: You can"t show the content without using 'print' if you're not using python
prompt ....

You can modify your function, so it prints if a second argument is given, and
doesn't print otherwise :

    
    
    def area_circle(r, do_print=False):
        a=r*r*pi
        if do_print:
            print(a)
        return a
    

This function will return the area in all the case. It will also print its
value if you give it `True` as a second argument (`area_circle(3)` prints
nothing and returns the area, while `area_circle(3,True)` print the area, and
also returns its value)

