python 格式化代码

YAPF https://github.com/google/yapf

1
2
3
4
# diff source
yapf --style='{based_on_style: google, indent_width: 2}' index.py -d
# replace source
yapf --style='{based_on_style: google, indent_width: 2}' index.py -i

可以写一个简单的脚本格式化文件或文件夹

file: pf

1
2
3
4
#!/bin/bash
FILE=$1
REPLACE=$2
yapf --style='{based_on_style: google, indent_width: 2}' $FILE $REPLACE

用法

1
2
3
4
# diff source
./pf index.py -d
# replace source
./pf index.py -i
Your browser is out-of-date!

Update your browser to view this website correctly. Update my browser now

×