Popular recipes tagged "print" but not "error"http://code.activestate.com/recipes/tags/print-error/2013-12-30T23:05:55-08:00ActiveState Code RecipesPretty Print table in tabular format (Python)
2013-12-30T23:05:55-08:00FB36http://code.activestate.com/recipes/users/4172570/http://code.activestate.com/recipes/578801-pretty-print-table-in-tabular-format/
<p style="color: grey">
Python
recipe 578801
by <a href="/recipes/users/4172570/">FB36</a>
(<a href="/recipes/tags/pretty_printer/">pretty_printer</a>, <a href="/recipes/tags/print/">print</a>, <a href="/recipes/tags/printer/">printer</a>, <a href="/recipes/tags/printf/">printf</a>, <a href="/recipes/tags/printing/">printing</a>).
</p>
<p>A simple function to Pretty Print a table in tabular format.</p>
<p>Table maybe a list of lists or list of tuples.</p>
<p>Justify and column width are optional parameters.</p>
Humanize decorator (Python)
2013-07-31T16:04:13-07:00tomer filibahttp://code.activestate.com/recipes/users/2520014/http://code.activestate.com/recipes/578619-humanize-decorator/
<p style="color: grey">
Python
recipe 578619
by <a href="/recipes/users/2520014/">tomer filiba</a>
(<a href="/recipes/tags/decorator/">decorator</a>, <a href="/recipes/tags/objects/">objects</a>, <a href="/recipes/tags/pretty/">pretty</a>, <a href="/recipes/tags/print/">print</a>).
</p>
<p>When you need to inspect Python objects in a human-readable way, you're usually required to implement a custom <code>__str__</code> or <code>__repr__</code> which are just boilerplate (e.g., <code>return "Foo(%r, %r, %r)" % (self.bar, self.spam, self.eggs)</code>. You may implement <code>__str__</code> and <code>__repr__</code> by a base-class, but it's hard to call it <em>inheritance</em> and moreover, you may wish to remove it when you're done debugging.</p>
<p>This simple (yet complete) recipe is a class decorator that injects <code>__str__</code> and <code>__repr__</code> into the class being printed. It handles nesting and even cycle detection, allowing you to just plug it into existing classes to get them pretty-printed and perhaps remove it later.</p>
Recursively print (nested) dictionaries (Python)
2012-04-04T15:20:42-07:00Mauricio Dada Fonseca de Freitashttp://code.activestate.com/recipes/users/4179701/http://code.activestate.com/recipes/578094-recursively-print-nested-dictionaries/
<p style="color: grey">
Python
recipe 578094
by <a href="/recipes/users/4179701/">Mauricio Dada Fonseca de Freitas</a>
(<a href="/recipes/tags/dictionary/">dictionary</a>, <a href="/recipes/tags/print/">print</a>, <a href="/recipes/tags/recursion/">recursion</a>).
</p>
<p>Snippet of code that uses recursion to print nested dictionaries.
It does not sort the entries!</p>
Printing with Python and pyGTK (Python)
2009-06-25T13:54:34-07:00Mark Muzenhardthttp://code.activestate.com/recipes/users/4170846/http://code.activestate.com/recipes/576820-printing-with-python-and-pygtk/
<p style="color: grey">
Python
recipe 576820
by <a href="/recipes/users/4170846/">Mark Muzenhardt</a>
(<a href="/recipes/tags/drawingarea/">drawingarea</a>, <a href="/recipes/tags/gtk/">gtk</a>, <a href="/recipes/tags/print/">print</a>, <a href="/recipes/tags/pygtk/">pygtk</a>).
Revision 2.
</p>
<p>PyGTK is a very powerful GUI-Toolkit. Nearly everything is well documented, except how to print. I messed around for hours just to solve this problem so I decided to share this cool piece of code!</p>
print variables as a dictionarly (Python)
2009-03-27T07:39:13-07:00Maxim Khesinhttp://code.activestate.com/recipes/users/2591465/http://code.activestate.com/recipes/576700-print-variables-as-a-dictionarly/
<p style="color: grey">
Python
recipe 576700
by <a href="/recipes/users/2591465/">Maxim Khesin</a>
(<a href="/recipes/tags/debugging/">debugging</a>, <a href="/recipes/tags/inspection/">inspection</a>, <a href="/recipes/tags/print/">print</a>).
Revision 2.
</p>
<p>Often I need to print some diagnostic variables and have to construct a format string to include both name and value; but there is a quicker way! This is especially useful for tracing function call values (foo in example below)</p>