【Day 19】瞄瞄 Python 标准函式库

稍微多了解一下标准函式库里面有什麽东西

今天才发现 Python 官方 document 就有官方教学还是繁体中文的~
https://docs.python.org/zh-tw/3/tutorial/index.html
然後针对标准函式库还有概览:
Python 标准函式库概览
Python 标准函式库概览——第二部份

这里把觉得 比较有用 或 可能忘记 的拿出来列一下,供日後翻阅。

系统 / 命令列

shutil:移动复制档案等,比 os 高阶的介面
sys.argv 拿命令列参数, argparse 有更多帮忙parse的功能

好用的 random

>>> import random
>>> random.choice(['apple', 'pear', 'banana'])
'apple'
>>> random.sample(range(100), 10)   # sampling without replacement
[30, 83, 16, 4, 8, 81, 41, 50, 18, 33]
>>> random.random()    # random float
0.17970987693706186
>>> random.randrange(6)    # random integer chosen from range(6)
4

好用的 datetime

>>> # dates are easily constructed and formatted
>>> from datetime import date
>>> now = date.today()
>>> now
datetime.date(2003, 12, 2)
>>> now.strftime("%m-%d-%y. %d %b %Y is a %A on the %d day of %B.")
'12-02-03. 02 Dec 2003 is a Tuesday on the 02 day of December.'

>>> # dates support calendar arithmetic
>>> birthday = date(1964, 7, 31)
>>> age = now - birthday
>>> age.days
14368

资料压缩

常见的解压缩以及压缩格式都有直接支援的模组。包括:zlibgzipbz2lzmazipfile 以及 tarfile

测效能

>>> from timeit import Timer
>>> Timer('t=a; a=b; b=t', 'a=1; b=2').timeit()
0.57535828626024577
>>> Timer('a,b = b,a', 'a=1; b=2').timeit()
0.54962537085770791

profile 模组以及 pstats 模组则提供了一些在大型的程序码识别时间使用上关键的区块 (time critical section) 的工具。

QA

weak references

weakref

array

array
元素都同类型的话可以放 array ,但好像都看人家用 numpy 的没在用内建的?


<<:  #19 No-code 之旅 — Avatars Libraries

>>:  Day19. 手牵手,我的朋友,物体永远在你左右 - Constraint

Kotlin Android 第8天,从 0 到 ML - 定义类别 / 初始化 / 继承

前言: 今天来看 类别 / 初始化 / 继承 大纲: class 结构 宣告 名称  主要建构式  ...

Day30 | 30天系列回顾 X赛程後规划

好啦,今天是第三十天了,今天会分享下赛程心得,并回顾一下前面系列文,最後是三十天後的规划! 参赛动机...

Day 10. 来学习如何切换场景!

碎碎念:虽然这部分VR的部分暂时消失了,但是这是因为我已经知道说,VR的部分是需要把接收输入的讯号改...

Day 10 - 宽高尺寸使用

既然昨天提到自订 spacing,width和height 也会跟着继承,今天威尔猪就来讲讲宽高的使...

【25】ReLU 家族评比 个别使用ReLU LeakyReLU PReLU SELU 来训练

Colab连结 今天要来实验不同的 ReLU 家族的评比,挑战者有 基本 ReLU 尾巴翘起来的 L...