def prettyPrintOpalDictHelper_(d, stream, indent, pretty_print=True, indent_additive=4): """Helper routine to print nested dicts and arrays with more structure""" # Base case, empty table entries = len(d) if entries == 0: print >> stream, "{ }", return # Recursive case print >> stream, "{", if pretty_print: print >> stream # Iterate through, printing each element ii = 0 keys = d.keys() keys.sort() for key in keys: # Sorted order on keys if pretty_print: indentOut_(stream, indent + indent_additive) opalPrintKey_(stream, key) # print >>stream, repr(key)+"=", value = d[key] specialStreamOpal_(value, stream, indent, pretty_print, indent_additive) if entries > 1 and ii != entries - 1: stream.write(",") if pretty_print: print >> stream ii += 1 if pretty_print: indentOut_(stream, indent) print >> stream, "}",
def prettyPrintOpalListHelper_(l, stream, indent, pretty_print=True, indent_additive=4): """Helper routine to print nested lists and arrays with more structure""" # Base case, empty table entries = len(l) if entries == 0: print >> stream, "{ }", return # Recursive case print >> stream, "{", if pretty_print: print >> stream # Iterate through, printing each element for ii in xrange(0, entries): if pretty_print: indentOut_(stream, indent + indent_additive) opalPrintKey_(stream, ii) specialStreamOpal_(l[ii], stream, indent, pretty_print, indent_additive) if entries > 1 and ii != entries - 1: stream.write(",") if pretty_print: print >> stream if pretty_print: indentOut_(stream, indent) print >> stream, "}",
def prettyPrintOpalDictHelper_ (d, stream, indent, pretty_print=True, indent_additive=4) : """Helper routine to print nested dicts and arrays with more structure""" # Base case, empty table entries = len(d) if entries==0 : print >>stream, "{ }", return # Recursive case print >>stream, "{", if pretty_print: print >>stream # Iterate through, printing each element ii=0 keys = d.keys() keys.sort() for key in keys : # Sorted order on keys if pretty_print : indentOut_(stream, indent+indent_additive) opalPrintKey_(stream, key) # print >>stream, repr(key)+"=", value = d[key] specialStreamOpal_(value,stream, indent, pretty_print, indent_additive) if entries>1 and ii!=entries-1 : print >>stream, ",", # Commas on all but last if pretty_print: print >>stream ii += 1 if pretty_print : indentOut_(stream, indent) print >>stream, "}",
def prettyOpal(value, stream=sys.stdout, starting_indent=0, indent_additive=4): """Output the given items in such a way as to highlight nested structures of dictionaries or Lists, but output as a Midas 2k OpalTable. By default, it prints to sys.stdout, but can easily be redirected to any file: >>> f = file('goo.txt', 'w') >>> pretty({'a':1}, f) >>> f.close() """ indentOut_(stream, starting_indent) pretty_print = 1 specialStreamOpal_(value, stream, starting_indent-indent_additive, pretty_print, indent_additive) if type(value) == type([]) or type(value)==type({}) : print >>stream
def prettyOpal(value, stream=sys.stdout, starting_indent=0, indent_additive=4): """Output the given items in such a way as to highlight nested structures of dictionaries or Lists, but output as a Midas 2k OpalTable. By default, it prints to sys.stdout, but can easily be redirected to any file: >>> f = file('goo.txt', 'w') >>> pretty({'a':1}, f) >>> f.close() """ indentOut_(stream, starting_indent) pretty_print = 1 specialStreamOpal_(value, stream, starting_indent - indent_additive, pretty_print, indent_additive) if type(value) == type([]) or type(value) == type({}): print >> stream
def prettyPrintOpalListHelper_ (l, stream, indent, pretty_print=True, indent_additive=4) : """Helper routine to print nested lists and arrays with more structure""" # Base case, empty table entries = len(l) if entries==0 : print >>stream, "{ }", return # Recursive case print >>stream, "{", if pretty_print: print >>stream # Iterate through, printing each element for ii in xrange(0,entries) : if pretty_print : indentOut_(stream, indent+indent_additive) opalPrintKey_(stream, ii) specialStreamOpal_(l[ii],stream, indent, pretty_print, indent_additive) if entries>1 and ii!=entries-1 : print >>stream, ",", # Commas on all but last if pretty_print: print >>stream if pretty_print : indentOut_(stream, indent); print >>stream, "}",