网络编程
位置:首页>> 网络编程>> Python编程>> python模块导入的方法

python模块导入的方法

作者:半屯澜湾  发布时间:2023-08-23 06:54:38 

标签:python,模块导入

模块在python编程中的地位举足轻重,熟练运用模块可以大大减少代码量,以最少的代码实现复杂的功能。

下面介绍一下在python编程中如何导入模块:

(1)import 模块名:直接导入,这里导入模块中的所有与函数;


import configparser
import time
import sys

这里的模块也可以是自己编写的脚本名称,如:


#hello.py
def hello1():
print("hello world!")
import hello

(2) from 模块名 import 函数名1[,函数名2,...] : 导入函数中的特定函数;


from requests import get
from requests import post
from platform import systey

(3)from 模块名 import *:导入所有函数, * 代表所有函数;


from wxpy import *

(4)import 模块名 as 别名:别名导入;


import configparser as cf
import time as T
import sys as sy

来源:https://www.cnblogs.com/xiaoyan-ipython/p/11729693.html

0
投稿

猜你喜欢

手机版 网络编程 asp之家 www.aspxhome.com