Config File Format
转载: TOML 教程 - 可能是目前最好的配置文件格式 - 知乎
配置文件是一种非常基础的文件格式,但远没有数据文件格式(如 SQLite)、文档文件格式(如 Markdown)、编程语言(JavaScript)、甚至二进制文件格式(如 PNG)需求那么复杂。只要严谨但不严苛、支持必要的数据类型和嵌套,又易于人类手工直接阅读和编辑就可以了。但就是这样一种广泛需要而又简单的应用场景,却反而长期以来一直没有一种足够好的文件格式。
#...
more...
Typescript Sample
# 安装 typescript
123npm install -g typescripttsc -v // 查看安装的版本
# 初始化 typescript 环境
tsc --init 初始化 tsconfig.json
"rootDir": "./src" 设定 typescript 源文件目录为 src, "outDir": "./out" 设定编译后的 js 文件目录为...
more...
Python Class
# 多继承顺序
super () 会沿着 __mro__ 顺序调用
123456789101112131415161718192021222324252627282930313233343536373839class D: passclass E: passclass B(D): passclass C(E): passclass A(B, C): pass# D E# B C# Aprint(A.__mro__)# (<class '__main__.A'>, <class...
more...
Python Yield
# 栈帧
栈帧就是一个函数执行的环境:函数参数、函数的局部变量、函数执行完后返回到哪里等等。python 中一且皆对象,运行函数前首先会创建栈帧 (stack frame) 对象,然后在这个上下文环境中运行字节码对象,所有的栈帧都是分配在堆内存上,不去释放就会一直存在,这就决定了栈帧可以独立于调用者存在。
123456789101112131415import inspectframe = Nonedef foo(): bar()def bar(): global frame frame =...
more...
Python Flask IIS
# 系統環境
繁体操作系統: Microsoft Windows Server 2012 R2 Standard
Python 版本:Python 3.6.2
Web 框架: Python Flask
服務器:IIS (Internet Information Services)
# 启动 IIS 服务,安裝 CGI
1 控制台 (檢視方式:類別) -> 程式集 -> 開啓或關閉 Windows 功能
2 安裝 IIS 管理工具和 CGI
IIS 管理工具
CGI 如果沒有安裝 CGI, 後續處理常式對應 會找不到 FastCgiModule
#...
more...
FTP and SFTP File Upload and Download
# FTP File Upload and Download
12345678910111213141516171819202122232425262728293031323334from ftplib import FTPimport timeimport osimport shutilport = 21def ftpconnect(host, port, username, password): ftp = FTP() ftp.set_debuglevel(2) # 打开调试级别2,显示详细信息 ftp.connect(host, port) # 连接...
more...
Python Iterable
# Iterator & Iterable
Iterable: 实现了 __iter__ 方法的对象
Iterator: 实现了 __iter__ 和 __next__ 方法的对象
Python 中关于迭代有两个概念,第一个是 Iterable,第二个是 Iterator,协议规定 Iterable 的 __iter__ 方法会返回一个 Iterator, Iterator 的 __next__ 方法(Python 2 里是 next)会返回下一个迭代对象,如果迭代结束则抛出 StopIteration 异常。同时,Iterator 自己也是一种...
more...
Python Send Mail
# send mail
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152import smtplibimport os.pathfrom email.mime.text import MIMETextfrom email.mime.multipart import MIMEMultipartfrom email.mime.application import MIMEApplicationport = 25smtp_server =...
more...
Python Logging
Remember, no matter what anyone says or tells you to do, look to yourself! What’s inside you is stronger than you spell. - Ella Enchanted
# 日志级别大小关系
CRITICAL > ERROR > WARNING > INFO > DEBUG > NOTSET
# 输出 log 到控制台
123456789101112import...
more...









