Page 75 -
P. 75
sharing your code
Now that you’ve added your comments and created a module, let’s test that your code is still working properly.
Rather than typing your function’s code into IDLE’s prompt, bring the nester.py file into IDLE’s edit window,
and then press F5 to run the module’s code:
Note that the
comments are
color coded.
Nothing appears to happen, other than the Python shell “restarting” and an empty prompt appearing:
>>> ================================ RESTART ================================
>>>
>>>
What’s happened is that the Python interpreter has reset and the code in your module has executed. The code
defines the function but, other than that, does little else. The interpreter is patiently waiting for you to do
something with your newly defined function, so let’s create a list of lists and invoke the function on it:
Define the list of movies facts
>>> movies = [
"The Holy Grail", 1975, "Terry Jones & Terry Gilliam", 91, from Chapter 1.
["Graham Chapman",
["Michael Palin", "John Cleese", "Terry Gilliam", "Eric Idle", "Terry Jones"]]]
>>> print_lol(movies)
Invoke the function on the list.
The Holy Grail
1975
Terry Jones & Terry Gilliam
Cool. Your code continues to
91
Graham Chapman function as expected. The data
Michael Palin in the list of lists is displayed
John Cleese on screen.
Terry Gilliam
Eric Idle
Terry Jones
you are here 4 39