title: Accessing global variable in python class __init__
body: <p>I am having an issue with accessing a globally declared variable in two separate classes. This is a kivy application that uses pandas for backend support.</p>
  
  <p>Here is the initialization of the global variable, <code>raw_data</code>, and where it is originally modified (in the <code>show_raw_data</code> func):</p>
  
  <pre><code># original dataframe
  raw_data = None
  
  class IntroScreen(Screen):
  
      def __init__ (self, **kwargs):
          super (IntroScreen, self).__init__(**kwargs)
  
          self.preview_screen_layout.add_widget(Button(text="View Raw Data", on_release=self.goto_raw_data))
  
      # switch to preview screen and show raw data when import is clicked
      def show_raw_data(self, *args):
          global file_path_list
          global raw_data
          try:
  
              # check input is correct
              if ".xlsx" in file_path_list["orig_data"]:
                  raise ValueError
              else:
                  # open csv file to display and display it
                  raw_data = pd.read_csv(file_path_list["orig_data"])
                  dfgui.show(raw_data)
  
                  # move to next screen
                  self.manager.current = 'preview_screen'
  </code></pre>
  
  <p>And here is where I am trying to access to be able to display the data that was read in using pandas:</p>
  
  <pre><code>class PreviewScreen(Screen):
  
      def __init__(self, **kwargs):
          super (PreviewScreen, self).__init__(**kwargs)
  
          global raw_data
          dfgui.show(raw_data)
  
      # display raw data to user 
      def goto_raw_data(self, *args):
          global raw_data
          dfgui.show(raw_data)
  </code></pre>
  
  <p>But here is my problem - in the PreviewScreen class, accessing the <code>global raw_data</code> within <code>goto_raw_data</code> works perfectly fine and <code>raw_data</code> contains the pandas dataframe, but when accessing the same global variable in the <code>__init__</code>, it is still initialized to <code>None</code> as it is in the original declaration. </p>
  
  <p>Is there something strange going on in my init function that is preventing the global variable from populating? I was thinking maybe the order in which the compiler reads the classes, but other than that I can't think of anything.</p>
  
  <p>Is there a way around this so that I can access the global variable in the <code>__init__</code> or am I stuck to accessing in a defined function.</p>
  
  <p>Thanks for any and all help!</p>