如何在 PyCharm 中“查看"/突出显示选项卡和空格以检查缩进? [英] How to 'see' / highlight tabs and spaces in PyCharm for checking indentation?

查看:169
本文介绍了如何在 PyCharm 中“查看"/突出显示选项卡和空格以检查缩进?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这听起来可能很愚蠢,但我还是个新手,是否有明确的方法可以发现 PyCharm 中的制表符或空格是否位于错误的位置?或者甚至可以直观地显示所有选项卡和空格?

this may sound dumb, but I am still fairly new, is there clear way to spot if I have tabs or spaces in the wrong place with PyCharm? Or even to display all tabs and spaces visually?

我花了很长时间在函数的 Def 行寻找无效语法"错误的问题,我原以为它可能仍然是一些错误的缩进,我以前确实有过,所以煞费苦心地检查了一下,但一无所获.最后,在此之前从函数结束处丢失了 ).我意识到右手边的彩色线条显示错误,并从那里得到了这个.

I just spent ages looking for problem with 'invalid syntax' error at Def line of function, I had thought it might still be some wrong indent, which I did have before, so checked this painstakingly and found nothing. In the end, was missing ) from end of function before this. I realised the coloured lines on right hand side show errors and got this one from there.

我也知道你可以在 PyCharm 中混合制表符和 4 个空格字符缩进没有问题?

Also I understand you can mix tabs and 4 space character indents in PyCharm with no problem?

但是,如果您在一行中使用制表符并在下一行中使用 4 个空格,例如,简单的文本编辑器,Python 会说‘不,我不会运行它,因为我是一个严格的学究,这太调皮了'?这方面还有其他常识性的最佳实践习惯吗?

But if you use tab one line and 4 spaces the next with, for example, simple text editor, Python will say 'no I'm not going to run this because I'm a strict pedant and this is just too naughty'? Any other common sense best practice habits in this area?

推荐答案

如何查看"/突出显示 PyCharm 中的制表符和空格以检查缩进?

How to 'see' / highlight tabs and spaces in PyCharm for checking indentation?

您可以通过转到 View -> Active Editor -> Show Whitespaces 来告诉 Pycharm 直观地显示制表符和空格:

You can tell Pycharm to visually show tabs and spaces by going to View -> Active Editor -> Show Whitespaces:

我也知道你可以在 PyCharm 中混合制表符和 4 个空格字符缩进没有问题?

Also I understand you can mix tabs and 4 space character indents in PyCharm with no problem?

是的,你可以.但你不应该.但是,即使您选择这样做,默认情况下 PyCharm 也会将它们全部转换为空格.您可以通过转到设置 -> 编辑器 -> 代码样式 -> Python,然后选择使用制表符复选框来更改此行为:

Yes you can. But you shouldn't. Even if you choose to however, PyCharm will convert them all to spaces by default. You can change this behavior by going to Settings -> Editor -> Code Style -> Python and then selecting the Use tab character check box:

这篇关于如何在 PyCharm 中“查看"/突出显示选项卡和空格以检查缩进?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆