在 PyCharm 中重新格式化长列表,使每行有一个项目

Reformat long list in PyCharm to have one item per line

提问人:Victor Di 提问时间:11/15/2023 更新时间:11/15/2023 访问量:29

问:

当我在 Pycharm 中进行代码格式化时,它会以这种方式重新格式化长列表:

style1 = [
    'Email:', 'SSN:', 'Address:', 'Home Phone:',
    'Mobile Phone: ', 'DOB:', 'Date of Surgery:',
    'Date of Service:', 'Facility of Service:', 'Clinic Number:',
    'Employer:', 'Work Phone: ', 'Fax: ', 'Type:', 'IPA:',
    'Health Plan:', 'ID #:', 'Claims Address:', 'Group #:',
    'Claim # / PO #:', 'Phone:', 'Fax:', 'Contact',
    'Adjuster Email', 'Util Review Phone', 'Util Review Fax',
    'Doctor:', 'NPI #: ', 'Date of Injury: ', 'Body Parts:',
    'Body Part Side:', 'Gender:', 'Diagnosis:', 'Diagnosis 2:',
    'Procedure:'
    ]

有没有办法在 PyCharm 中重新格式化并每行有一个项目,如下所示:

style2 = [
    'Email:',
    'SSN:',
    'Address:',
    'Home Phone:',
    'Mobile Phone: ',
    'DOB:',
    'Date of Surgery:',
    'Date of Service:',
    'Facility of Service:',
    'Clinic Number:',
    'Employer:',
    'Work Phone: ',
    'Fax: ',
    'Type:',
    'IPA:',
    'Health Plan:',
    'ID #:',
    'Claims Address:',
    'Group #:',
    'Claim # / PO #:',
    'Phone:',
    'Fax:',
    'Contact',
    'Adjuster Email',
    'Util Review Phone',
    'Util Review Fax',
    'Doctor:',
    'NPI #: ',
    'Date of Injury: ',
    'Body Parts:',
    'Body Part Side:',
    'Gender:',
    'Diagnosis:',
    'Diagnosis 2:',
    'Procedure:'
    ]

我试图用.editconfig来做到这一点,但还没有找到一个可以解决问题的参数。

蟒蛇 pycharm

评论

1赞 AKX 11/15/2023
我只需选择块,然后查找并替换为(启用正则表达式模式),然后再次重新格式化以修复缩进。', '',\n'
0赞 AKX 11/15/2023
(或者,您可以使用 Black 或 ;它会以类似的方式设置列表的格式。ruff format
0赞 Brian61354270 11/15/2023
PyCharm 原生支持使用 black 进行代码格式化。通常建议使用标准格式而不是个人风格。黑色将使用此列表的格式,每行一个条目
0赞 bad_coder 12/4/2023
这回答了你的问题吗?在doctest的文档字符串的行前面添加“>>>”的快捷方式吗?
0赞 bad_coder 12/4/2023
使用 AKX 的建议,关于使用 find&rereplace 有很多问题......

答: 暂无答案