打卡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("测试通过!")  

@浙大疏锦行

相关推荐
2601_967987374 小时前
Python 教程:默认字典(defaultdict)全维度深度指南
python·性能优化·数据处理·collections·defaultdict
鱼听禅5 小时前
Ubuntu安装YOLOv8进行菌落识别训练
linux·python·yolo·ubuntu
ZhengEnCi5 小时前
Agent 查不出代码 Bug 怎么办:一份带时间戳的调试日志与读日志排查流程
python·ai编程
瑞雪兆丰年兮5 小时前
JavaWeb-day14-SpringBootWeb原理篇
java·开发语言·spring boot·spring·bean·mybatis·javaweb
威哥爱编程6 小时前
模拟面试智能体开发实战 05:给面试官接上题库和检索,题目结构化、大纲可溯源,AI 不再凭印象出题
python·agent·harmonyos
威哥爱编程6 小时前
模拟面试智能体开发实战 06:答得好怎么追问、答得错怎么点破,追问引擎让面试官会深挖会纠错
python·agent·harmonyos
codists7 小时前
《crafting interpreters》阅读笔记:4.6.2
python
2601_967979127 小时前
机器学习必修课:经典算法与Python实战
python·算法·机器学习·实战·课程
SomeOtherTime7 小时前
Rust生命周期介绍(AI回答)
开发语言·后端·rust
程序猿打工仔7 小时前
计算机基础(C语言)考编、专技岗
c语言·开发语言·算法