python模块导入的方法

yipeiwu_com6年前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

以上就是本次介绍的全部相关知识点,感谢大家的阅读和对【听图阁-专注于Python设计】的支持。

相关文章

python实现在windows下操作word的方法

本文实例讲述了python实现在windows下操作word的方法。分享给大家供大家参考。具体实现方法如下: import win32com from win32com.client...

Python的Bottle框架中实现最基本的get和post的方法的教程

Python的Bottle框架中实现最基本的get和post的方法的教程

1、GET方式:    # -*- coding: utf-8 -*- #!/usr/bin/python # filename: GETPOST_test.p...

Python3.6实现带有简单界面的有道翻译小程序

本人使用的是Python3.6(32bit),在win10上运行的     代码如下: from tkinter import * import url...

Django命名URL和反向解析URL实现解析

Django命名URL和反向解析URL实现解析

命名 URL: test.html: <!DOCTYPE html> <html lang="en"> <head> <meta cha...

python无序链表删除重复项的方法

python无序链表删除重复项的方法

题目描述: 给定一个没有排序的链表,去掉重复项,并保留原顺序 如: 1->3->1->5->5->7,去掉重复项后变为:1->3->5->...