How to import python class file from same directory?

前端 未结 2 1650
一生所求
一生所求 2021-02-01 02:41

I have a directory in my Python 3.3 project called /models.

from my main.py I simply do a

from models import *

in my __

2条回答
  •  一向
    一向 (楼主)
    2021-02-01 03:07

    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"
    

提交回复
热议问题