title: ImportError: cannot import X from the file that has if __name__ == "__main__". Any solutions without delete if __name__ == "__main__"?
body: <p>I have 2 files <code>n1711_001_insilico</code> and <code>n1711_002_insilico</code> in the same folder. I want two variables (<code>mzdf</code> which is <code>&lt;class 'pandas.core.frame.DataFrame'&gt;</code>, and <code>charge</code> is<code>'int'</code>) from the first file so I do <code>import</code> at the top of the second file:</p>
  
  <pre><code>import numpy as np
  import pandas as pd
  from n1711_001_insilico import mzdf, charge
  </code></pre>
  
  <p>I got <code>ImportError: cannot import name mzdf</code>(as well as for <code>charge</code>). In the first file, I explicitly return both <code>mzdf</code> and <code>charge</code> from the function and call them like this:</p>
  
  <pre><code>if __name__ == "__main__":
      mzdf, charge = CALC(peptides_report, aa_dict, charge_from=1, charge_to=6)
  </code></pre>
  
  <p>Update: from the comment I now know the issue comes from <code>if __name__ == "__main__":</code> in the first file. Any ways that I can fix this without deleting <code>if __name__ == "__main__"</code>?</p>