python之导入模块的方法

一、导入标准库模块
1、第一种方式:
可以通过以下方法导入
1 import time
当使用时间模块的sleep方法时可以使用
1 time.sleep(2)
2、第二种方式:
当只想使用sleep函数时,可以通过以下方法
1 from time import sleep
2 sleep(2)
 
 
二、导入第三方库模块
通过pip install xxxx 安装的模块,直接import即可加载
1 import selenium

 直接使用其中的方法也是可以的

1 from selenium import webdriver
三、导入自定义模块
1、第一种方式
将多个脚本均放置在同一个文件夹下面
通过import 文件名导入模块并且可调用其模块下的方法
 
1 import fuction2
2 x=fuction2.fu2(10)
3 print(x)
查看执行结果:
 

2、第二种方式

直接导入模块下的方法
1 from fuction3 impo fu3
2 y=fu3(10)
3 print(y)
查看执行结果:
 
原文地址:https://www.cnblogs.com/mrwhite2020/p/12892205.html