Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Importing <code>file2</code> in <code>file1.py</code> makes the global (i.e., module level) names bound in <code>file2</code> available to following code in <code>file1</code> -- the only such name is <code>SomeClass</code>. It does <strong>not</strong> do the reverse: names defined in <code>file1</code> are not made available to code in <code>file2</code> when <code>file1</code> imports <code>file2</code>. This would be the case even if you imported the right way (<code>import file2</code>, as @nate correctly recommends) rather than in the horrible, horrible way you're doing it (if everybody under the Sun forgot the very existence of the construct <code>from ... import *</code>, life would be <em>so</em> much better for everybody).</p> <p>Apparently you want to make global names defined in <code>file1</code> available to code in <code>file2</code> <em>and</em> vice versa. This is known as a "cyclical dependency" and is a <em>terrible</em> idea (in Python, or anywhere else for that matter).</p> <p>So, rather than showing you the incredibly fragile, often unmaintainable hacks to achieve (some semblance of) a cyclical dependency in Python, I'd much rather discuss the many excellent way in which you can <strong>avoid</strong> such terrible structure.</p> <p>For example, you could put global names that need to be available to both modules in a <em>third</em> module (e.g. <code>file3.py</code>, to continue your naming streak;-) and import that third module into each of the other two (<code>import file3</code> in both <code>file1</code> and <code>file2</code>, and then use <code>file3.foo</code> etc, that is, <em>qualified</em> names, for the purpose of accessing or setting those global names from either or both of the other modules, <strong>not</strong> barenames).</p> <p>Of course, more and more specific help could be offered if you clarified (by editing your Q) exactly <em>why</em> you think you need a cyclical dependency (just one easy prediction: no matter what makes you think you need a cyclical dependency, you're wrong;-).</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload