Page 163 -
P. 163

persistence




                              Let’s add a fourth argument to your print_lol() function to identify a place to write your
                          1
                              data to. Be 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.
                              Fill in the blanks with the details of your new argument. (Note: to save on space, the comments
                              have been removed from this cod, but be sure to update your comments in your nester.py
                              module after you’ve amended your code.)




                      def print_lol(the_list, indent=False, level=0,                      ):


                          for each_item in the_list:
                              if isinstance(each_item, list):
                                  print_lol(each_item, indent, level+1,          )
                              else:
                                  if indent:
                                      for tab_stop in range(level):
                                          print("\t", end='',                )
                                  print(each_item,                     )



                      What needs to happen to the code in your with statement now that your amended print_lol()
                  2
                      function is available to you?













                      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().












                                                                                      you are here 4    127
   158   159   160   161   162   163   164   165   166   167   168