10.标准库简介

1.操作系统接口

import os
os.getcwd()
os.chdir('')#切换当前工作目录
os.system('mkdir today')#执行命令
dir(os)
help(os)

import shutil

2.文件通配符

  • glob模块提供了一个在目录中使用通配符搜索创建文件列表的函数

3.命令行参数

import sys
print(sys.argv)

4.错误输出重定向和程序终止

stdin、stdout、stderr

5.字符串模式匹配

re模块
'one and too'.replace('too','two')
=》'one and two'
import re
re.findall
re.sub

6.数学

import math
math.cos(math.pi/4)
math.log(1024,2)

import random
random.choice([2,4,1])

选一个

random.sample(range(100),10)

抽样,抽10个

import statistics
data=[1,2,4,7,3]
statistics.mean(data)#算术平均
statistics.median(data)#中位数
statistics.variance(data)#方差

7.互联网访问

urllib.request用于从URL检索数据
smtplib用于发送邮件

8.日期和时间

from datetime import date
now=date.today()

9.数据压缩

import zlib

10.性能测量

from timeit import Timer
Timer('代码').timeit()

11.质量控制

  • doctest模块用于扫描模块并验证程序文档字符串中嵌入的测试
    doctest.testmod()
  • uinttest模块

12.自带电池

  • xmlrpc.client\xmlrpc.server
  • email
  • json
  • sqlite3
  • xml.etree.ElementTree
  • xml.dom
  • xml.sax
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 上班的时候偷懒,把Python帮助里的标准功能库1过了一遍,顺便翻译了一下,虽然我知道基本没有人看,但不是说21世...
    哪儿黑阅读 407评论 1 5
  • 操作系统接口 os模块提供了不少与操作系统相关联的函数。 >>> import os >>> os.getcwd(...
    chen_000阅读 915评论 0 1
  • rljs by sennchi Timeline of History Part One The Cognitiv...
    sennchi阅读 7,449评论 0 10
  • pyspark.sql模块 模块上下文 Spark SQL和DataFrames的重要类: pyspark.sql...
    mpro阅读 9,505评论 0 13
  • 今天开半年会,感觉这半年差的还很多,付出的不够,还需要更佳努力,像标杆学习,加油
    88e94d537f85阅读 74评论 0 0