简体   繁体   English

Pycharm没有重新格式化代码

[英]Pycharm is not reformatting code

I have heritage code in python with semicolon at the end of each line and mixed tab and spaces indentation. 我在python的每一行末尾都有分号和混合制表符和空格的缩进的传统代码。
PyCharm reports it at code inspection and suggest to reformat code. PyCharm在代码检查时报告它,并建议重新格式化代码。 The problem is that when I click "Reformat Code" (which IDE recommends), Pycharm does nothing - code still contains semicolons and mixed indentation. 问题是,当我单击“重新格式化代码”(IDE建议)时,Pycharm不会执行任何操作-代码仍然包含分号和混合缩进。
Why Code Reformat does not work? 为什么代码重新格式化不起作用?

Sample code: 样例代码:

for i in config.args.include:       
    if i.count(":") == 2:
        path, output, prefix = i.split(":");
    elif i.count(":") == 1:
        path, prefix = i.split(":");
        output = os.path.splitext(path)[0] + ".h";
    else:
        utils.fatal("Incorrect -a paramter tuple specification");

Please give the code example. 请给出代码示例。 ; ; at the end of line is not a python syntax. 行尾不是python语法。 ; ; is ignored in workable code. 在可行的代码中被忽略。 But PyCharm cannot parse for example: 但是PyCharm无法解析例如:

print "fdfdf"; for x in [1, 2, 3]: print("dsds")    print "d"

Ctrl+Alt+L: Ctrl + Alt + L:

print "fdfdf"; for x in [1, 2, 3]: print("dsds")
print "d"

But can parse: 但是可以解析:

print "fdfdf"   for x in [1, 2, 3]: print("dsds")    print "d"

to

print "fdfdf"
for x in [1, 2, 3]: print("dsds")
print "d"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM