title: Initialize common variables used in mutiple classes Python
body: <p>Assuming that I have two classes A and B. In class A, B's instances will created. Both of their instance methods will use a common variable, which is initialized in class A. I have to pass the common_var through the <strong>init</strong> function. Think that if I have classes A, B, C, D.... and common_var1, var2, var3...where all vars have to be passed through class to class, that’s terrible:</p>
  
  <pre><code>class A:
      def __init__(self, variable_part):
          self.common_var = "Fixed part" +　variable_part
          self.bList = []
  
      def add_B(self):
          self.bList += [B(self.common_var)]
  
      def use_common_var():
          do_something(self.common_var)
  
  class B:
      def __init__(self, common_var):
          self.common_var = common_var
  
      def use_common_var():
          do_something(self.common_var)
  </code></pre>
  
  <p>There's an ugly approach to use <strong>global</strong> here:</p>
  
  <pre><code>class A:
      def __init__(self, variable_part):
          global common_var
          common_var = "Fixed part" +　variable_part
  
      def use_common_var(self):
          do_something(common_var)
  
  class B:
      def use_common_var(self):
          do_something(common_var)
  </code></pre>
  
  <p>But I don't think it's a good idea, any better ideas?</p>
  
  <h2>Update:</h2>
  
  <p>The original question is here:</p>
  
  <p>The common_vars are a series of prefixes of strings, things like <code>"https://{}：{}/rest/v1.5/".format(host, port)</code>, <code>"mytest"</code> etc..</p>
  
  <p>and in class A, I use</p>
  
  <pre><code>"https://127.0.0.1:8080/rest/v1.5/interface01" and "mytest_a"
  </code></pre>
  
  <p>in class B, I use</p>
  
  <pre><code>"https://127.0.0.1:8080/rest/v1.5/interface02" and "mytest_b"
  </code></pre>
  
  <p>in class C, I may use</p>
  
  <pre><code>"https://127.0.0.1:8080/rest/v1.5/get?name=123" and "mytest_c"
  </code></pre>
  
  <p>things like that, I use common variables just to multiplex <code>'https://{}:{}/rest/v1.5'</code> and <code>"mytest"</code> part and none of these A, B, C classes is in "is-a" relationship. But the core part of this problem is the common_var is not common at very first but initialized in one of this class..</p>
  
  <hr>
  
  <h2>Final Update</h2>
  
  <p>I compromised. I added a <strong>Helper</strong> class to reuse the common values:</p>
  
  <pre><code>class Helper:
      @staticmethod
      def setup(url, prefix):
          Helper.COMMON_URL = url
          Helper.prefix = prefix
  
  # A always initiates first
  Class A: 
      def __init__(self, host, port):
          Helper.setup(
              "https://{0}:{1}/rest/v1.5".format(host, port),
              "test"
          )
  
      def use_common_var():
          do_something(Helper.url, Helper.prefix)
  
  
  class B:
      def use_common_var():
          do_somesthing(Helper.url, Helper.prefix)
  
  
  class C:
      def use_common_var():
          do_something(Helper.url, Helper.prefix)
  </code></pre>
  
  <p>Is this a better way?</p>