title: Why does this Python code get the name error?
body: <p>I want to have attribute that is shared by and accessible to all instances of a class.</p>
  
  <p>Sample code:</p>
  
  <pre><code>class Test:
  
      code = [ 1, 2, 3, 5, 6, 7, 8, 9, 10]
      code2d = [ [ code[j*3 + i] for i in range(3) ] for j in range(3) ]
  
      def __init__(self):
          pass
  </code></pre>
  
  <p>However, I get error: </p>
  
  <blockquote>
    <p>NameError: name 'code' is not defined</p>
  </blockquote>
  
  <p>If I put the lines with <code>code</code> and <code>code2d</code> into init method, all is working properly.</p>
  
  <p>Why this code throws the error?</p>