Page 164 -
P. 164
extend your function
You were to add a fourth argument to your print_lol() function to identify a place to write
1
your data to, being sure to give your argument a default value of sys.stdout so that it
continues to write to the screen if no file object is specified when the function is invoked.
You were to fill in the blanks with the details of your new argument. (Note: to save on space, the
comments have been removed from this code, but be sure to update those in your nester.py
module after you’ve amended your code).
Add the fourth argument and give it a
default value.
fh=sys.stdout
def print_lol(the_list, indent=False, level=0, ):
for each_item in the_list:
if isinstance(each_item, list): Note: the
fh signature has
print_lol(each_item, indent, level+1, ) changed.
else:
if indent:
for tab_stop in range(level): Adjust the two
calls to “print()”
file=fh
print("\t", end='', ) to use the new
file=fh
print(each_item, ) argument.
What needs to happen to the code in your with statement now that your amended print_lol()
2
function is available to you?
The code needs to be adjusted so that instead of using the
“print()” BIF, the code needs to invoke “print_lol()” instead.
List the name of the module(s) that you now need to import into your program in order to support your
3
amendments to print_lol().
The program needs to import the amended “nester” module.
128 Chapter 4