The closest working thing to your code would be:
==== FILE: b.py ====
class B:
def __init__(self):
print "B"
import a
if __name__ == "__main__":
a = a.A()
==== FILE: a.py ====
import b
class A(b.B): ###=> B is not defined
def __init__(self):
print "A"
Notice the differences:
Files (modules) are namespaces, if you import "a" you refer to its class A as "a.A".
You need to import b in a.py if you want to use it.
You want to avoid having two modules that need to include each other, by either putting everything in the same module, or splitting things up in more modules. Also, it's better to have all your imports at the head of the file, which makes this kind of monkeying impossible.