change in import handling / modules from python2 to python3?

前端 未结 2 2012
日久生厌
日久生厌 2021-01-05 08:19

I was trying to following the design pattern shown in this previous question related to SQLAlchemy and intended to share a common Base instance across multiple files. The co

2条回答
  •  死守一世寂寞
    2021-01-05 09:19

    One solution I found is to:

    • move the code from base.py to __init__.py.
    • change the import base lines in a.py, b.py, and c.py to from . import Base
    • in model.py change from model import base to from model import Base
    • also in model.py change base.Base to Base.

    I'm still uncertain why the previous design works in python2 but not python3. The changes above make it work in both python2 and python3.

提交回复
热议问题