首页 > 编程 > Python > 正文

python模块导入的方法

2019-11-25 11:32:58
字体:
来源:转载
供稿:网友

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

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

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

import configparserimport timeimport sys

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

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

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

from requests import getfrom requests import postfrom platform import systey

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

from wxpy import *

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

import configparser as cfimport time as Timport sys as sy

以上就是本次介绍的全部相关知识点,感谢大家的阅读和对武林网的支持。

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表