title: Python class constructor (static)
body: <p>Does Python have a mechanism for class constructors, i.e. a function that is called whenever the class is first referenced (as opposed to when an instance of that object is created)? I know this exists in some other languages, but I haven't come across it in Python.</p>
  
  <p>Basically, I would like to initialise some static attributes in that function. I put an example below of what I would expect. Of course, the example returns None, but I would like it return 'foo'.</p>
  
  <pre><code>class T:
      arg = None
      def __class_constructor__():
          T.arg = 'foo'
  
  print(T.arg)  # returns None
  </code></pre>
  
  <p>To avoid confusion: I am well aware of the object constructor, but that's not what I want, because it is only called once the first object is created, not before:</p>
  
  <pre><code>class T:
      arg = None
      def __init__(self):
          type(self).arg = 'foo'
  
  print(T.arg)  # returns None
  obj = T()
  print(T.arg)  # returns 'foo'
  </code></pre>