title: How can I define a class attribute from a variable in Python?
body: <p>I need to access a variable from a nested class. The objective is to create a Schema using the Marshmallow library. The code looks like this :</p>
  
  <pre><code>class ParserScheme(Schema):
  
      class Meta:
          # Here I meed to access the value of my_variable :
          result = func(my_variable)
  
  my_variable = 'foo'
  my_parser = ParserScheme()
  </code></pre>
  
  <p>If I manage to pass my variable as a class attribute of the outer class (ParserScheme), then it is easy to get it into the inner class (Meta).</p>
  
  <pre><code>class ParserScheme(Schema):
      class_attribute = my_variable
      class Meta:
          result = func(ParserScheme.class_attribute)
  
  my_variable = 'foo'
  my_parser = ParserScheme()
  </code></pre>
  
  <p>However I can't seem to find a way to dynamically set a class attribute. And if I set a "classic" attribute (I mean an attribute of instances of the class, not of the class itself), then I can't access it from the inner class.</p>
  
  <p>I also thought of using a global variable, but that does not really quite satisfy me. Is there another way of doing this ?</p>
  
  <p>I am rather new to OOP, and I am not sure I understand really well the concept of class attribute. I fear that there is an easy way to do that but I did not see it as I am to focused on the way I think this should work...</p>