python - Formatting numpy arrays with black
问题描述
I am using vscode along with black as a formatter. I don't like how it formats numpy arrays and how it is effected by line length, for example
F = np.array([[1, 1, 0, 0, 0, 0], [0, 0, 1, 1, 0, 0], [0, 0, 0, 0, 1, 1]])
versus
F = np.array(
[
[1, 1, 0.5, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 1, 1, 0.5, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 1, 1, 0.5],
]
)
For readability I prefer the latter, but black formats the latter style when the former style would violate the line length.
Is there a way to customize black to prefer formatting the latter style without changing the line length parameter.
I am open to other formatters, I am just using black because it interfaces nice with flake8. My line length is set to 88.
解决方案
黑色只有两个配置选项:
- 线长
- 是否将
'
引号替换为"
如果您想要这种级别的配置,您可能需要查看 autopep8 或 yapf。
推荐阅读
- javascript - 在每次鼠标移动时,可拖动元素的位置都被重置为零
- angular - Angular 4 库 - 使用 webpack 更新到 v.5
- javascript - 如何使用javascript重新映射数组
- javascript - 格式化内容和显示媒体
- javascript - 无法使用 javascript 读取未定义的属性“”
- c# - 使用 AddTraceSource 的 dotnet 核心日志记录不起作用
- node.js - 如何在nodejs中阻止服务器终止?
- hibernate - 在一对多关系中更新父实体时如何更新子实体?
- android - 如何使用从屏幕中间开始的 TabLayout 垂直滚动整个内容?
- ios - 溢出滚动不工作IOS