title: How to exchange variables between different python files?
body: <p>I've 2 python files file1.py and file2.py in the same directory.</p>
  
  <pre class="lang-py prettyprint-override"><code>#file1.py
  
  import file2 as f2
  
  graph={ 0: [1,2],
          1: [0,3,2,4],
          2: [0,4,3,1],
          3: [1,2,5],
          4: [2,1,5],
          5: [4,3]
        }
  
  def function1(graph):
     print(f2.C1)
  </code></pre>
  
  <p>The other file is</p>
  
  <pre class="lang-py prettyprint-override"><code>#file2.py
  
  import file1 as f1
  
  graph=f1.graph
  
  def function2(graph):
  
  #Perform some operation on graph to return a dictionary C
  
      return C
  
  
  C1=function2(graph)
  </code></pre>
  
  <p>When I run file1, I'm getting an error</p>
  
  <pre class="lang-py prettyprint-override"><code>module 'file2' has no attribute 'C1'
  </code></pre>
  
  <p>And when I run file2 and try to check the value of C1 variable, I'm getting an error:</p>
  
  <pre><code>module 'file1' has no attribute 'graph'
  </code></pre>
  
  <p>What should I do to import these files correctly so as to exchange the values between the files appropriately?</p>
  
  <p>Note that when I implement the variable graph in file2 directly instead of fetching from file1, it works perfectly, but it starts creating an issue when the variables are exchanged between the files.</p>
  
  <p>Edited:</p>
  
  <p>I've added more refined version of the code to simplify the problem.</p>
  
  <pre class="lang-py prettyprint-override"><code>#file1
  
  import file2 as f2
  
  def fun1(graph):
     C=[None]*20
      for i in range(20):
          # Some algorithm to generate the subgraphs s=[s1,s2,...,s20]
          C[i]=f2.fun2(s[i]) 
          print(C[i])
  
  
  
  graph={ 0: [1,2],
          1: [0,3,2,4],
          2: [0,4,3,1],
          3: [1,2,5],
          4: [2,1,5],
          5: [4,3]
        } 
  
  def getGraph():
      return graph
  
  fun1(graph)
  
  </code></pre>
  
  <p>Other file file2.py</p>
  
  <pre><code>import file1 as f1
  
  
  graph_local=f1.getGraph()
  
  #Some operations on graph_local to generate another graph 'graph1' of same "type" as graph_local
  
  def fun2(graph1):
  
     #Perform some operation on graph1 to return a dictionary C
  
      return C
  
  </code></pre>
  
  <p>If I create a test.py as mentioned <a href="https://stackoverflow.com/a/55705055/7447425">here</a>,</p>
  
  <pre class="lang-py prettyprint-override"><code>#test.py
  
  from file1 import fun1
  
  fun1(None)
  
  </code></pre>
  
  <p>When I run test.py or file2.py, the error is</p>
  
  <pre><code>module 'file1' has no attribute 'getGraph'
  </code></pre>
  
  <p>whereas when I run file1.py,</p>
  
  <pre><code>module 'file2' has no attribute 'C'
  </code></pre>