9.2加载模块

import sys
from pprint import pprint
pprint(sys.path) 输出结果:
['D:\\myproject\\python_lxf',
'D:\\myproject\\python_lxf',
'D:\\soft\\PyCharm 2019.3.3\\plugins\\python\\helpers\\pycharm_display',
'D:\\soft\\python36\\python36.zip',
'D:\\soft\\python36\\DLLs',
'D:\\soft\\python36\\lib',
'D:\\soft\\python36',
'D:\\soft\\python36\\lib\\site-packages',
'D:\\soft\\python36\\lib\\site-packages\\geventhttpclient_wheels-1.3.1.dev2-py3.6-win-amd64.egg',
'D:\\soft\\python36\\lib\\site-packages\\win32',
'D:\\soft\\python36\\lib\\site-packages\\win32\\lib',
'D:\\soft\\python36\\lib\\site-packages\\Pythonwin',
'D:\\soft\\PyCharm '
'2019.3.3\\plugins\\python\\helpers\\pycharm_matplotlib_backend']

默认的模块加载路径

>>> import sys
>>> sys.path.append('/Users/michael/my_py_scripts')

添加自己的搜索目录

9.4查看模块内容

dir(): 返回模块或类所包含的全部程序单元(包括变量、函数、类和方法等)

__all__:模块本身提供的变量,不会展示以下划线开头的程序单元。另使用from xx import *,是不会导入以下划线开头的程序单元的

import logging,pprint
pprint.pprint(dir(logging))
['BASIC_FORMAT',
'BufferingFormatter',
'CRITICAL',
'DEBUG',
'ERROR',
'FATAL',
'FileHandler',
'Filter',
'Filterer',
'Formatter',
'Handler',
'INFO',
'LogRecord',
'Logger',
'LoggerAdapter',
'Manager',
'NOTSET',
'NullHandler',
'PercentStyle',
'PlaceHolder',
'RootLogger',
'StrFormatStyle',
'StreamHandler',
'StringTemplateStyle',
'Template',
'WARN',
'WARNING',
'_STYLES',
'_StderrHandler',
'__all__',
'__author__',
'__builtins__',
'__cached__',
'__date__',
'__doc__',
'__file__',
'__loader__',
'__name__',
'__package__',
'__path__',
'__spec__',
'__status__',
'__version__',
'_acquireLock',
'_addHandlerRef',
'_checkLevel',
'_defaultFormatter',
'_defaultLastResort',
'_handlerList',
'_handlers',
'_levelToName',
'_lock',
'_logRecordFactory',
'_loggerClass',
'_nameToLevel',
'_releaseLock',
'_removeHandlerRef',
'_showwarning',
'_srcfile',
'_startTime',
'_warnings_showwarning',
'addLevelName',
'atexit',
'basicConfig',
'captureWarnings',
'collections',
'critical',
'currentframe',
'debug',
'disable',
'error',
'exception',
'fatal',
'getLevelName',
'getLogRecordFactory',
'getLogger',
'getLoggerClass',
'info',
'io',
'lastResort',
'log',
'logMultiprocessing',
'logProcesses',
'logThreads',
'makeLogRecord',
'os',
'raiseExceptions',
'root',
'setLogRecordFactory',
'setLoggerClass',
'shutdown',
'sys',
'threading',
'time',
'traceback',
'warn',
'warning',
'warnings',
'weakref']
pprint.pprint(logging.__all__)
['BASIC_FORMAT',
'BufferingFormatter',
'CRITICAL',
'DEBUG',
'ERROR',
'FATAL',
'FileHandler',
'Filter',
'Formatter',
'Handler',
'INFO',
'LogRecord',
'Logger',
'LoggerAdapter',
'NOTSET',
'NullHandler',
'StreamHandler',
'WARN',
'WARNING',
'addLevelName',
'basicConfig',
'captureWarnings',
'critical',
'debug',
'disable',
'error',
'exception',
'fatal',
'getLevelName',
'getLogger',
'getLoggerClass',
'info',
'log',
'makeLogRecord',
'setLoggerClass',
'shutdown',
'warn',
'warning',
'getLogRecordFactory',
'setLogRecordFactory',
'lastResort',
'raiseExceptions']

dir()、__all__

使用__doc__属性查看文档。另:使用help()函数查看的其实就是程序单元的__doc__属性值

import string
help(string.capwords)
Help on function capwords in module string:
capwords(s, sep=None)
capwords(s [,sep]) -> string Split the argument into words using split, capitalize each
word using capitalize, and join the capitalized words using
join. If the optional second argument sep is absent or None,
runs of whitespace characters are replaced by a single space
and leading and trailing whitespace are removed, otherwise
sep is used to split and join the words.
print(string.capwords.__doc__)
capwords(s [,sep]) -> string
Split the argument into words using split, capitalize each
word using capitalize, and join the capitalized words using
join. If the optional second argument sep is absent or None,
runs of whitespace characters are replaced by a single space
and leading and trailing whitespace are removed, otherwise
sep is used to split and join the words.

__doc__与help()

使用__file__属性查看模块的源文件路径

import string
string.__file__
'E:\\soft\\Python\\Python36\\lib\\string.py'

__file__

python学习-模块与包(九)的更多相关文章

  1. python学习——模块和包

    在之前常用模块中我们已经初步了解了模块的导入,今天来说学习一下模块和包.我们可以把模块理解成每一个python文件.而包就是多个能解决一类问题的python文件全部放在一起.OK

  2. Python之模块和包导入

    Python之模块和包导入 模块导入: 1.创建名称空间,用来存放模块XX.py中定义的名字 2.基于创建的名称空间来执行XX.py. 3.创建名字XX.py指向该名称空间,XX.名字的操作,都是以X ...

  3. 一文搞懂 Python 的模块和包,在实战中的最佳实践

    最近公司有个项目,我需要写个小爬虫,将爬取到的数据进行统计分析.首先确定用 Python 写,其次不想用 Scrapy,因为要爬取的数据量和频率都不高,没必要上爬虫框架.于是,就自己搭了一个项目,通过 ...

  4. Python之模块和包学习

    模块简介 python是由一系列的模块组成的,每个模块就是一个py为后缀的文件,同时模块也是一个命名空间,从而避免了变量名称冲突的问题.模块我们就可以理解为lib库,如果需要使用某个模块中的函数或对象 ...

  5. selenium + python自动化测试unittest框架学习(四)python导入模块及包知识点

    在写脚本的时候,发现导入某些模块,经常报错提示导入模块失败,这里来恶补下python导入模块的知识点. 1.模块导入时文件查找顺序 在脚本中,import xxx模块时的具体步骤: (1)新建一个mo ...

  6. python基础-------模块与包(一)

    模块与包 Python中的py文件我们拿来调用的为之模块:主要有内置模块(Python解释器自带),第三方模块(别的开发者开发的),自定义模块. 目前我们学习的是内置模块与第三方模块. 通过impor ...

  7. (Python )模块、包

    本节开始学习模块的相关知识,主要包括模块的编译,模块的搜索路径.包等知识 1.模块 如果我们直接在解释器中编写python,当我们关掉解释器后,再进去.我们之前编写的代码都丢失了.因此,我们需要将我们 ...

  8. python 浅析模块,包及其相关用法

    今天买了一本关于模块的书,说实话,模块真的太多了,小编许多也不知道,要是把模块全讲完,可能得出本书了,所以小编在自己有限的能力范围内在这里浅析一下自己的见解,同时讲讲几个常用的模块. 这里是2018. ...

  9. python中模块、包、库的区别和使用

    模块:就是.py文件,里面定义了一些函数和变量,需要的时候就可以导入这些模块. 包:在模块之上的概念,为了方便管理而将文件进行打包.包目录下第一个文件便是 __init__.py,然后是一些模块文件和 ...

随机推荐

  1. Day 26 网络基础 3

    tcpdump抓包 tcpdump -i eth0 port 80 -nn -S -i 指定网卡 port 指定端口号 http 80:ftp 21 :ssh 22:telnet 23:smtp 25 ...

  2. day 12 特殊权限

    1.suid (set uid) 特殊权限 suid优点: 可以让普通用户执行无法执行的命令 方便 suid缺点: 如果rm 为suid, 无论谁执行该命令,都能删除系统的任何 资源 set uid ...

  3. 【Sentinel】sentinel 集成 apollo 最佳实践

    [Sentinel]sentinel 集成 apollo 最佳实践 前言   在 sentinel 的控制台设置的规则信息默认都是存在内存当中的.所以无论你是重启了 sentinel 的客户端还是 s ...

  4. 03 (OC)* UITableView优化

    一:cell注册和初始化 1:不注册cell 2:注册类 3:注册nib 4:storyboard 二:核心思想 1:UITableView的核心思想是:cell的重用机制.UITbleView只会创 ...

  5. Java线程池的拒绝策略

    一.简介 jdk1.5 版本新增了JUC并发编程包,极大的简化了传统的多线程开发.前面文章中介绍了线程池的使用,链接地址:https://www.cnblogs.com/eric-fang/p/900 ...

  6. ActiveMQ JMX使用

    一.说明 ActiveMQ使用过程中,可以使用自带的控制台进行相关的操作以及查看,但是当队列数相当多的时候,在查询以及整体的监控上,就可能相当的不便.所以可通过JMX的方式,进行MQ中队列相关指标的以 ...

  7. Linux 文件/目录操作详解

    目录 Linux 文件/目录操作详解 初识Linux 一.文件/目录显示命令 ls 二.目录创建命令 mkdir 三.目录转移命令 cd 四.当前目录显示命令 pwd 五.文件处理命令 rmdir 六 ...

  8. Linux版本号的数值含义

    Linux内核版本有两种:稳定版和开发版 ,Linux内核版本号由3组数字组成:第一个组数字.第二组数字.第三组数字.第一个组数字:目前发布的内核主版本.第二个组数字:偶数表示稳定版本:奇数表示开发中 ...

  9. C# 事件 Event

    一.事件是什么 微软的定义:和委托类似,事件是后期绑定机制. 实际上,事件是建立在对委托的语言支持之上的.事件是对象用于(向系统中的所有相关组件)广播已发生事情的一种方式. 任何其他组件都可以订阅事件 ...

  10. maven手动添加jar包到pom仓库

    此处以顺丰jar包为例: mvn install:install-file -Dfile=D:\TSBrowserDownloads\SF-CSIM-EXPRESS-SDK-V1.-\SF-CSIM- ...