Python importing

前端 未结 4 494
春和景丽
春和景丽 2021-01-20 03:23

I have a file, myfile.py, which imports Class1 from file.py and file.py contains imports to different classes in fi

4条回答
  •  礼貌的吻别
    2021-01-20 04:11

    In the myfile module, you can either do from file import ClassFromFile2 or from file2 import ClassFromFile2 to access ClassFromFile2, assuming that the class is also imported in file.

    This technique is often used to simplify the API a bit. For example, a db.py module might import various things from the modules mysqldb, sqlalchemy and some other helpers. Than, everything can be accessed via the db module.

提交回复
热议问题