BRIEF TOUR OF THE STANDARD LIBRARY — PART II CHAPTER ELEVEN 11.1 Output Formatting This second tour covers more advanced modules that support professional programming needs. These modules rarely occur in small scripts. The$_{reprlib}$module provides a version of$_{repr()}$ customized for abbreviated displays of large or deeply nested containers: The$_{pprint}$module offers more sophisticated control over printing both built-in and user defined objects in a way that is readable by the interpreter. When the result is longer than one line, the “pretty printer” adds line breaks and indentation to more clearly reveal data structure: The$_{textwrap}$module formats paragraphs of text to fit a given screen width: The$_{locale}$ module accesses a database of culture specific data formats. The grouping attribute of locale’s format function provides a direct way of formatting numbers with group separators: (continues on next page) 85 >>> import locale >>> locale.setlocale(locale .LC_ALL, 'English_United States.1252 ') 'English_United States.1252' >>> import textwrap >>> doc =""" The wrap() method is just like fill() except that it returns ... a list of strings instead of one big string with newlines to separate ... the wrapped lines. """ ... >>> print(textwrap .fill(doc, width =40 )) The wrap() method is just like fill() except that it returns a list of strings instead of one big string with newlines to separate the wrapped lines. >>> import pprint >>> t =[[[['black','cyan'],'white ', ['green','red']], [['magenta', ... 'yellow'],'blue']]] ... >>> pprint.pprint(t, width =30 ) [[[['black', 'cyan'], 'white', ['green', 'red']], [['magenta', 'yellow'], 'blue']]] >>> import reprlib >>> reprlib.repr(set('supercalifragilisticexpialidocious')) "{'a', 'c', 'd', 'e', 'f', 'g', ...}"