Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>As mentioned by others, in one case it's an attribute on the class on the other an attribute on the instance. Does this matter? Yes, in one case it does. As Alex said, if the value is mutable. The best explanation is code, so I'll add some code to show it (that's all this answer does, really):</p> <p>First a class defining two instance attributes.</p> <pre><code>&gt;&gt;&gt; class A(object): ... def __init__(self): ... self.number = 45 ... self.letters = ['a', 'b', 'c'] ... </code></pre> <p>And then a class defining two class attributes.</p> <pre><code>&gt;&gt;&gt; class B(object): ... number = 45 ... letters = ['a', 'b', 'c'] ... </code></pre> <p>Now we use them:</p> <pre><code>&gt;&gt;&gt; a1 = A() &gt;&gt;&gt; a2 = A() &gt;&gt;&gt; a2.number = 15 &gt;&gt;&gt; a2.letters.append('z') </code></pre> <p>And all is well:</p> <pre><code>&gt;&gt;&gt; a1.number 45 &gt;&gt;&gt; a1.letters ['a', 'b', 'c'] </code></pre> <p>Now use the class attribute variation:</p> <pre><code>&gt;&gt;&gt; b1 = B() &gt;&gt;&gt; b2 = B() &gt;&gt;&gt; b2.number = 15 &gt;&gt;&gt; b2.letters.append('z') </code></pre> <p>And all is...well...</p> <pre><code>&gt;&gt;&gt; b1.number 45 &gt;&gt;&gt; b1.letters ['a', 'b', 'c', 'z'] </code></pre> <p>Yeah, notice that when you changed, the mutable class attribute it changed for all classes. That's usually not what you want.</p> <p>If you are using the ZODB, you use a lot of class attributes because it's a handy way of upgrading existing objects with new attributes, or adding information on a class level that doesn't get persisted. Otherwise you can pretty much ignore them.</p>
    singulars
    1. This table or related slice is empty.
    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. 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