Python 跨目录模块引用

案例:调用School目录下的Student模块

# import time
import random
from time import sleep

from School.Student import Student

num=random.randint(1,10)
print(num)
sleep(5)    #5秒钟后打印出Sleep over!
print("Sleep over!")

stu1=Student('jack','Beijing')
stu2=Student('harry','Shanghai')

在这里插入图片描述
import 搜索路径
当你导入一模块,Python解析器对模块位置的搜索顺序是:
1.当前目录
2.如果不在当前目录,Python则搜索PYRHONPATH下的每个目录
3.如果都找不到,Python会察看安装默认路径。

猜你喜欢

转载自blog.csdn.net/weixin_43264177/article/details/82900035
今日推荐