Author: ChrisZZ
imzhuo@foxmail.com
Create: 2023.05.08 12:20:00
Last Modified: 2023.05.08 12:23:00
1. Python 在 Windows 下的补全
pip install pyreadline3
2. 操作注册表: winreg
模块
包括且不限于如下作用:
获取实时更新的环境变量取值
获取安装了的 Visual Studio 的版本
3. 命令行调试 python 程序
使用 pdb 模块作为调试器:
python -m pdb xxx.py
注意必须提供文件名字, 这和 GDB/LLDB 不太一样。也就是说 PDB 并不是和 GDB/LLDB 兼容的, 因此在 Vim 中使用 Termdebug
时无法很好的使用 PDB 调试 Python 。
4. 列出所有模块
import sys
modules = sorted(sys.modules.keys())
for item in modules:
print(item)
5. 类型注解(type hints)
函数参数增加类型: : type
函数返回值增加类型: -> type :
def add(x, y):
return x + y
def add(x: int, y: int) -> int :
return x + y
注意, type hints 并不是给到 Python 解释器做真正的类型检查, 仅仅是给人看的。也就是说你可以不按 type hints 给的类型来传入参数, 也能得到结果:
def my_add(x: int, y: int) -> int:
return x + y
c = my_add(2.4, 5.5)
print(c) # 7.9