博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Python import相关内容区别介绍( import *** as 、from***import )
阅读量:4075 次
发布时间:2019-05-25

本文共 706 字,大约阅读时间需要 2 分钟。

        在python中import或者from…import是用来导入相应的模块。那每一种有什么具体的差别呢?

一、import

        只有import,为最简单的引入对应的包。例如:

import pickle   #引入 pickle包import os       #引入 os包
二、from A import B

        这种方式意味着从A中引入B。相当于:import A, b=A.b。

from urllib.parse import urlparsefrom sys import argv

        除了这种基本形式,还有另外两种,例如:

from os import makedirs, unlink, sep                  #从os包中引入 makedirs.unlink,sep类from os import listdir, getcwd                        #从os包中引入 listdir, getcwd 类from os.path import dirname, exists, isdir, splitext  #从 os包中的path类中引入 dirmame exists 方法from os.path import join                              #从 os包中的path类中引入 join 方法
三、import A as B

        这种方式为给引入的包A定义一个别名B,例如:

import xml.etree.ElementTree as ET   #给包xml.etree.ElementTree 定义一个 ET 别名

转载地址:http://cfyni.baihongyu.com/

你可能感兴趣的文章
CentOS Tensorflow 基础环境配置
查看>>
centOS7安装FTP
查看>>
FTP的命令
查看>>
CentOS操作系统下安装yum的方法
查看>>
ping 报name or service not known
查看>>
FTP 常见问题
查看>>
zookeeper单机集群安装
查看>>
do_generic_file_read()函数
查看>>
Python学习笔记之数据类型
查看>>
Python学习笔记之特点
查看>>
shell 快捷键
查看>>
VIM滚屏操作
查看>>
EMC 2014存储布局及十大新技术要点
查看>>
linux内核内存管理(zone_dma zone_normal zone_highmem)
查看>>
将file文件内容转成字符串
查看>>
循环队列---数据结构和算法
查看>>
优先级队列-数据结构和算法
查看>>
链接点--数据结构和算法
查看>>
servlet中请求转发(forword)与重定向(sendredirect)的区别
查看>>
Spring4的IoC和DI的区别
查看>>