Sean Mackesey
Sean Mackesey

Reputation: 10939

Inheriting from a class defined in an imported module in Python

I have two Python classes in two separate modules. The modules reference each other, so I must use the import XXX syntax rather than from XXX import YYY. I can't figure out how to access a class defiend in one module in the other, importing module though:

### testa.py

import testb

class TestA():
  ...

### testb.py

import testa

class TestB(testa.TestA):  # doesn't work
  ...

How do I do this?

Upvotes: 0

Views: 55

Answers (1)

univerio
univerio

Reputation: 20508

You can solve this by putting import testb after the definition of TestA. However, you might need to rethink your module structure since circular imports are difficult to deal with.

Upvotes: 1

Related Questions