我正在学习使用python编程,从软件包中的模块导入时遇到问题。我已经测试过注释掉启用了jedi的部分,但是它不起作用。我正在将Visual Studio代码与Python 3.8.2 64位一起使用。
在我写的products.py文件中:
从.database导入数据库p =数据库(3,2)
以便我可以从database.py模块导入Database类
任何帮助将不胜感激
由于您使用的是Python 3.8版本,因此导入的工作方式略有不同,但是我认为这应该有效:
使用任一:
from database import Database
#Database is the class
或尝试:
import database.Database
最后,这是一个非常安全的做法,并且可能是最佳做法:
from . import Database
# The '.' (dot) means from within the same directory as this __init__.py module grab the Database class.