title: passing a variable from class to another class python
body: <p>i have a python game.py script that runs 3 stages using 3 files named stage1, stage2, stage3, and it works as it should, however on adding new features to my game when trying to get a variable from a class in stage2 to stage3 i just can not seem to get it right. The stage1 generates a var(random string name), i save the variable as machine_id here is a sample,</p>
  <h2>Edited ## The game.py starts the 3 stages as follows below</h2>
  <pre><code>class Main:
  
      def run_stage1(self):
          start_stage1 = stage1.Stage1() 
          unique_machine_id = start_stage1.start()
          return unique_machine_id
  
      def run_stage2(self):
          start_stage2 = stage2.Stage2()  
          list_of_players = start_stage2.start()  
          return list_of_players
      
      def run_stage3(self, key, path):
          start_stage3 = stage3.Game(key, path)  
          start_stage3.game_start() 
  </code></pre>
  <p>main_folder</p>
  <pre><code> game.py
  
   sub_folder
  </code></pre>
  <p>sub_folder</p>
  <pre><code>stage1
  stage2
  stage3
  
              
  </code></pre>
  <p>stage2 below creates a unique machine_id for each player,</p>
  <pre><code>#This is stage2
  
      def start_gui(machine_id): 
          root1 = tk.Tk() 
          top = Toplevel1(root1, machine_id)
          root1.mainloop()
  
  class Toplevel1:
      def __init__(self, top=None, machine_id=&quot;TEST MACHINE ID&quot;):
          self.machine_id = machine_id     
          &quot;&quot;&quot;other code and functions below, and passing machine_id within same class i can do&quot;&quot;&quot;
  
  
  if __name__ == '__main__':
      start_gui(&quot;555f9f3b573f4c41e7de2c5b3f97ed54&quot;)  #Takes Machine ID As Argument
  </code></pre>
  <p>what i am trying to do is pass the machine id to stage3</p>
  <p>stage 3 below.</p>
  <pre><code>#This is stage3
  
  
  from sub_folder import stage2        #&lt;- imported stage2
  
  class Stage3:
      def __init__(self):
          fetch_var_machine_id = stage2.Toplevel1(self, machine_id)  # &lt;&lt; This is what i am using but it does not pass the variable.
          print(fetch_var_machine_id)  # &lt;This Just Returns 'S' Not the machine_id
  
      def start(self, fetch_var_machine_id):
          &quot;&quot;&quot;Do stuff&quot;&quot;&quot;
          return &quot;&quot;&quot;Do Stuff&quot;&quot;&quot;
  </code></pre>
  <p>This is an example of how i have been trying to pass the Machine id from one class to another without success. i can not seem to understand with other tutorials</p>