我尝试使用autopep8格式化某些python代码,期望除其他事项外,分隔超过80个字符的注释行。我使用了这个测试文件test.py
,它仅包含注释:
#asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf
#asdf asdf asdf asdf
#asdf asdf asdf asdf
#asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf
#asdf asdf asdf asdf
#asdf asdf asdf asdf
#asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf
然后我运行了
autopep8 test.py
这给出了以下输出:
# asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf
# asdf asdf asdf asdf
# asdf asdf asdf asdf
# asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf
# asdf asdf asdf asdf
# asdf asdf asdf asdf
# asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf
# asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf
最后一条长行被分割,但前两行没有被分割。我认为所有行都应以80个字符的宽度折断。我究竟做错了什么?
最佳答案
autopep8不会自动修复所有长行;仅在被视为“安全”的情况下才这样做。看:
https://github.com/hhatto/autopep8/issues/39
关于python - Autopep8不会中断较长的注释行吗?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/21439063/