# Print a newline and a separator prior to printing the first module section print "\n" print '=' * 65 # for each of the modules we have, create a line of versions, wrap the # description and whatis text, for module, data in sorted(modules_dict.items()): versions = data['versions'] versions.sort() versions = ', '.join(sorted(versions)) desc_lines = [] desc_line_len = 65 desc = '' if 'whatis' in data: desc = data['whatis']['Description'] desc = wrap_lines(desc, desc_line_len) try: description = '\n'.join(wrap_lines(modules_dict[module]['whatis']['Description'], desc_line_len)) vers = ', '.join(modules_dict[module]['versions']) vers = wrap_lines(vers, desc_line_len - 12) vers = '\n'.join(vers) print "Module name: %s" % module print "Versions:", vers print '-' * 65 print "Description\n\n", description print '\n' print '=' * 65 except: continue
from wrap_lines import wrap_lines # Set variables for testing # Text from module description that will wrap to at least three lines desc = 'Universal Mathematical Suite is a Python library that allows you to define, optimize, and evaluate mathematical expressions involving multi-dimensional arrays efficiently. It is built with GPU support.' versions = ['1.1', '1.2', '1.3', '2.1', '2.2'] vers = ', '.join(versions) # This is here to look ahead to when we have a module name # (short) and a package name like this as a separate # field. module = "Universal Mathematical Suite" # We wrap all the fields their column widths m = wrap_lines(module, 20) v = wrap_lines(vers, 12) d = wrap_lines(desc, 48) # Initialize the table header = ['Module', 'Versions', 'Description'] table = PrettyTable(header) table.align = 'l' # There will always be a first row, so we just add it table.add_row([m[0], v[0], d[0]]) # Set the counter for how many rows we've printed count = 1 # We have something to add if there are still lines left in