我在 VSCode 中使用 Black 來格式化 python,它使我的所有陣列都超高而不是寬。我已將 pep8 和 flake8 和黑色的最大行長度設定為 150(但我是 Black 的新手,不確定它是否使用這些設定中的任何一個):
"python.formatting.blackArgs": ["--line-length", "150"],
這是它的外觀:
expected = make_dict_of_rows(
[
10,
11,
15,
24,
26,
30,
32,
35,
36,
37,
50,
53,
54,
74,
76,
81,
114,
115,
118,
119,
120,
123,
],
)
是我得到的,而不是更簡潔的:
expected = make_dict_of_rows(
[
10, 11, 15, 24, 26, 30, 32, 35, 36, 37, 50, 53, 54, 74, 76, 81, 114, 115, 118, 119, 120, 123,
],
)
(或者更可取的是,這會有一些折疊的括號):
expected = make_dict_of_rows([
10, 11, 15, 24, 26, 30, 32, 35, 36, 37, 50, 53, 54, 74, 76, 81, 114, 115, 118, 119, 120, 123
])
uj5u.com熱心網友回復:
如果串列末尾有逗號,黑色將始終將串列分解為多行。您可以洗掉黑色的尾隨逗號以壓縮串列。您還可以使用--skip-magic-trailing-comma:
"python.formatting.blackArgs": ["--line-length", "150", "--skip-magic-trailing-comma"],
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/528397.html
