How do most people do console.log debugging in Python?
<p>In Node.js when I want to quickly check the value of something rather than busting out the debugger and stepping through, I quickly add a console.log(foo) and get a beautiful:</p>

<pre><code>{
   lemmons: "pie",
   number: 9,
   fetch: function(){..}
   elements: {
      fire: 99.9
   }
}
</code></pre>

<p>Very clear! In Python I get this:</p>

<pre><code>class LinkedList:
  head = None
  tail = None
  lemmons = 99
</code></pre>

<p><code>&lt;__main__.LinkedList instance at 0x105989f80&gt;</code>
or with <code>vars()</code>,</p>

<p><code>{}</code></p>

<p>or with <code>dir()</code>, </p>

<p><code>['_LinkedList__Node', '__doc__', '__module__', 'append', 'get_tail', 'head', 'lemmons', 'remove', 'tail']</code></p>

<p>Yuck! Look at all that nonsense - I thought python was supposed to be fast, beautiful and clean? Is this really how people do it? Do they implement customer <strong>str</strong> and custom <strong>repr</strong> for everything? Because that seems kind of crazy too..</p>

<p>You can print your objects &amp; Python classes in a lot of different ways, here's a simple one:</p>

<pre><code>class LinkedList:
    head = None
    tail = None
    lemmons = 99

    def __str__(self):
        return str(vars(LinkedList))

print LinkedList()
</code></pre>

<p>I'd recommend you start for getting familiar with <a href="http://stackoverflow.com/questions/1436703/difference-between-str-and-repr-in-python"><strong>str</strong> and <strong>repr</strong></a> operators. In any case, this is a little example and with python there are tons of ways to pretty print object &amp; classes</p>

python class debugging object tostring