How to Break Import Loop in python
<p>I have a situation where there two related large  python classes and hence i have put them in separate files. Let say classes are Cobra and Rat.</p>

<p>Now need to call methods of Rat from methods of Cobra and vice versa.
For this i need to import Cobra in Rat.py and Rat in Cobra.py</p>

<p>This creates an import loop and gives an error. Cant import Cobra inside Cobra.</p>

<p>How to fix this??</p>

<pre><code>import Rat
Class Cobra:
...
def check_prey(self, rat ):
    Some logic rat.foo()



import Cobra
class Rat
...
def check_predator(self, snake ):
   some_logic ..
   snake.foo()
</code></pre>
