加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
format_coding_style.py 1000 Bytes
一键复制 编辑 原始数据 按行查看 历史
Arendelle 提交于 2024-09-21 14:40 . fix coding style
import os
def main():
for root, dirs, files in os.walk("physicsLab"):
try:
dirs.remove("__pycache__")
except ValueError:
pass
for file in files:
with open(os.path.join(root, file), encoding="utf-8") as f:
lines = f.read().splitlines()
context: str = ""
for line_num, line in enumerate(lines):
while line.endswith(' '):
line = line[:-1]
if len(line) > 120:
print(f"{os.path.join(root, file)} {line_num + 1}: this line is TOO LONG({len(line)}/120)")
context += line + '\n'
context = context[:-1]
while context.endswith('\n'):
context = context[:-1]
if not context.endswith('\n'):
context += '\n'
with open(f"{root}/{file}", "w", encoding="utf-8") as f:
f.write(context)
if __name__ == "__main__":
main()
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化