打卡day30

知识点回顾:

  1. 导入官方库的三种手段
  2. 导入自定义库/模块的方式
  3. 导入库/模块的核心逻辑:找到根目录(python解释器的目录和终端的目录不一致)

作业:自己新建几个不同路径文件尝试下如何导入

复制代码
from lib.utils import add  
from lib.sublib.helper import helper_func  
print(add(2, 3))  
print(helper_func(3))  
def add(a, b):  
    return a + b  
from ..utils import add  
def helper_func(x):  
    return add(x, x)  
import sys  
sys.path.append('../')  
from lib.utils import add  
def test_add():  
    assert add(1, 2) == 3, "测试失败"  
test_add()  
print("测试通过!")  

@浙大疏锦行

相关推荐
小小测试开发4 小时前
安装 Python 3.10+
开发语言·人工智能·python
梦想不只是梦与想4 小时前
Python 中的装饰器
python·装饰器
我叫唧唧波5 小时前
Python+AI 全栈学习笔记
人工智能·python·学习
AAA大运重卡何师傅(专跑国道)5 小时前
【无标题】
开发语言·c#
copyer_xyf5 小时前
Python 异常处理
前端·后端·python
XBodhi.6 小时前
Visual Studio C++ 语法错误: 缺少“;”(在“return”的前面)
开发语言·c++·visual studio
麻雀飞吧6 小时前
期货多合约策略目标持仓怎么更新才不乱
python·区块链
Cthy_hy6 小时前
拓扑排序超详解:原理 + Kahn 贪心算法
python·算法·贪心算法
LSssT.6 小时前
【01】Python 机器学习
开发语言·python
为爱停留6 小时前
给智能体装上「刹车」:中断(Interrupts)与人工审批全解析
python