Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The <code>__repr__</code> should return a string that describes the object. If possible, it should be a valid Python expression that evaluates to an equal object. This is true for built-in types like <code>int</code> or <code>str</code>:</p> <pre><code>&gt;&gt;&gt; x = 'foo' &gt;&gt;&gt; eval(repr(x)) == x True </code></pre> <p>If that's not possible, it should be a <code>'&lt;...&gt;'</code> string uniquely describing the object. The default <code>__repr__</code> is an example of this:</p> <pre><code>&gt;&gt;&gt; class Foo(object): pass &gt;&gt;&gt; &gt;&gt;&gt; repr(Foo()) '&lt;__main__.Foo object at 0x02A74E50&gt;' </code></pre> <p>It uses the object's address in memory to uniquely identify it. Of course address doesn't tell us much about the object so it's useful to override <code>__repr__</code> and return a string describing the object's state.</p> <p>The object's state is defined by other objects it contains so it makes sense to include their <code>repr</code> in yours. This is exactly what <code>list</code> or <code>dict</code> do:</p> <pre><code>&gt;&gt;&gt; repr(['bar', Foo()]) "['bar', &lt;__main__.Foo object at 0x02A74710&gt;]" </code></pre> <p>In your case, the state is in your <code>Column</code> properties so you want to use their <code>repr</code>. You can use the <code>%r</code> formatting for this, it inserts a <code>repr()</code> of the argument:</p> <pre><code>def __repr__(self): return '&lt;Stats: description=%r, mystat=%r&gt;' % (self.description, self.mystat) </code></pre> <p>An equivalent using the new formatting:</p> <pre><code>def __repr__(self): return '&lt;Stats: description={0.description!r}, mystat={0.mystat!r}&gt;'.format(self) </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload