06模块与包回顾

模块与包回顾

# 模块
	-一个py 文件,导入使用,他就是模块
    -一个py,点右键运行,他叫 脚本文件
# 包
	-一个文件夹下 有 __init__.py ,下面又有很多文件夹和py文件,导入使用的
    
    
# 以后只要看到这个报错
	ModuleNotFoundError: No module named 'xx' ,但是这个模块有
    
    导入的问题:路径不对
    
# 相对导入和绝对导入
	-1 相对导入,相对于:当前py文件
    	-当前py文件
        -当前执行的脚本文件
        
        -坑,如果py文件中使用了相对导入,他就不能右键运行了
        
    -2 绝对导入:相对于环境变量  sys.path
    	- 项目根路径
        - site-packages 下载的第三方模块
        -python内置的,都在环境变量中
    
['D:\\Python\\PythonProjects28\\demo001', 'D:\\Python\\PythonProjects28\\demo001', 'D:\\Python\\PyCharm\\plugins\\python\\helpers\\pycharm_display', 'D:\\Python\\Python310\\python310.zip', 'D:\\Python\\Python310\\DLLs', 'D:\\Python\\Python310\\lib', 'D:\\Python\\Python310', 'D:\\Python\\Python310\\lib\\site-packages', 'D:\\Python\\PyCharm\\plugins\\python\\helpers\\pycharm_matplotlib_backend']


# 以后django,在同一个app下
	-建议:相对导入
    	from .views import index
    -如果用绝对导入:
    	from app01.views import index
posted @ 2024-05-15 16:54  Formerly0^0  阅读(11)  评论(0)    收藏  举报