4

Python模块的使用 | CHEGVA

 1 year ago
source link: https://chegva.com/5426.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Python进阶(19)—模块的使用

◎知识点

  1. 使用当前项目中的模块

  2. 导入的不同模块中存在相同的属性

  3. import语句的执行流程

  4. 解释器搜索模块的路径

◎脚本练习

▽ 使用当前项目中的模块

"""
如果想要使用当前项目中的模块,必须通过import语句进行导入。有三种导入方式:
1. 直接导入
2. 绝对导入
3. 相对导入
"""

"""
1. 直接导入
    直接导入当前目录中的模块名
    
2. 绝对导入
    导入模块名的绝对路径
    
3. 相对导入
    导入模块名的相对路径。其中,一个.表示当前目录,两个..表示当前目录的父目录
    当直接运行某个模块时,该模块就变成了主模块。主模块位于最顶层,与同目录下的其它模块无法构成相对关系
    因此,当直接运行某个模块时,该模块不能使用相对导入
"""
Python
安志合个人博客,版权所有 丨 如未注明,均为原创 丨 转载请注明转自:https://chegva.com/5426.html | ☆★★每天进步一点点,加油!★★☆ | 

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK