title: How do I assign an object to a variable in one module and then access it from another module?
body: <p>I have two modules. Module1 is the main program and module2 is utility code. The utility code needs to access a list that lives in module1. But module1 needs to choose which of two lists will be operative before calling into module2. The problem is that module2 seems unable to access the current value of the module1 variable. Example code:</p>
  <pre><code># module1.py
  #!python
  
  import module2
  
  list1 = [1,2,3]
  list2 = [4,5,6]
  
  chosen_list = []
  
  def main():
      print('here')
      
      global chosen_list
  
      chosen_list = list2
      
      module2.do_func()
  
  if __name__ == '__main__':
      main()
  
  
  # module2.py
  #!python
  
  import module1
  
  def do_func():
      print(module1.chosen_list[2])
  </code></pre>
  <p>This produces the error: IndexError: list index out of range</p>
  <p>If I don't assign chosen_list to anything at module scope I get AttributeError: module 'module1' has no attribute 'chosen_list'.</p>
  <p>If I assign chosen_list to list1 at module scope I get the values of list1 from module2, not the values of list2.</p>
  <p>So how do I get chosen_list to be list2 in module2 as a result of operations done in main()?</p>
  <p>Note that this question is NOT a duplicate of <a href="https://stackoverflow.com/questions/15234288/making-a-variable-accessible-for-any-other-module">Making a variable accessible for any other module</a> because the answer in that one is simply to properly refer to modulename.variablename. My issue is about the values of the variables, not the scope and name. I was told to ask another question, which is lame, but here it is.</p>