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

@浙大疏锦行

相关推荐
未来可期叶1 小时前
如何用Python批量解压ZIP文件?快速解决方案
python
张槊哲1 小时前
ROS2架构介绍
python·架构
风逸hhh2 小时前
python打卡day29@浙大疏锦行
开发语言·前端·python
浩皓素2 小时前
深入理解For循环及相关关键字原理:以Python和C语言为例
c语言·python
英英_2 小时前
详细介绍一下Python连接MySQL数据库的完整步骤
数据库·python·mysql
ᖰ・◡・ᖳ2 小时前
JavaScript:PC端特效--缓动动画
开发语言·前端·javascript·css·学习·html5
水花花花花花2 小时前
GloVe 模型讲解与实战
python·深度学习·conda·pip
C_VuI2 小时前
如何安装cuda版本的pytorch
人工智能·pytorch·python
Star abuse2 小时前
机器学习基础课程-6-课程实验
人工智能·python·机器学习
hy____1233 小时前
C++多态的详细讲解
开发语言·c++