How to import python class file from same directory? How to import python class file from same directory? python-3.x python-3.x

How to import python class file from same directory?


Since you are using Python 3, which disallows these relative imports (it can lead to confusion between modules of the same name in different packages).

Use either:

from models import finding

or

import models.finding

or, probably best:

from . import finding  # The . means "from the same directory as this module"


Apparently I can do: from .finding import Finding and this works.

And the answer below reflects this as well so I guess this is reasonably correct.

I've fixed up my file naming and moved my tests to a different directory and I am running smoothly now. Thanks!