问题:pycharm自动将制表符转换为空格

我正在使用pycharm IDE进行python开发,它对Django代码非常完美,因此怀疑将制表符转换为空格是默认行为,但是在python IDE中到处都有错误,因为它无法自动将制表符转换为空格,有没有一种方法可以实现这个。

I am using pycharm IDE for python development it works perfectly fine for django code so suspected that converting tabs to spaces is default behaviour, however in python IDE is giving errors everywhere because it can’t convert tabs to spaces automatically is there a way to achieve this.


回答 0

更改代码样式以使用空格而不是制表符:

空格

然后在项目视图中选择要转换的文件夹并使用Code| 重新格式化代码

Change the code style to use spaces instead of tabs:

spaces

Then select a folder you want to convert in the Project View and use Code | Reformat Code.


回答 1

对于选择,还可以使用“到空格”功能转换选择。我通常只通过ctrl-shift-A使用它,然后从那里找到“到空格”。

For selections, you can also convert the selection using the “To spaces” function. I usually just use it via the ctrl-shift-A then find “To Spaces” from there.


回答 2

这只会转换选项卡,而不会更改其他任何内容:

Edit -> Convert Indents -> To Spaces

This only converts the tabs without changing anything else:

Edit -> Convert Indents -> To Spaces

回答 3

CTRL + SHIFT + A =>打开弹出窗口来选择选项,选择为空格到所有标签转换为空间,或以标签的所有空间转换为制表。

ctrl + shift + A => open pop window to select options, select to spaces to convert all tabs as space, or to tab to convert all spaces as tab.


回答 4

PyCharm 2019.1

如果要更改常规设置:

开放的喜好,在MacOS上;或在Windows / Linux的Ctrl+ Alt+S

转到“编辑器”->“代码样式”->“ Python”,如果要遵循PEP-8,请选择“ 制表符大小:4”,“ 缩进:4 ”和“ 继续缩进:8”,如下所示:

在此处输入图片说明

应用更改,然后单击“确定”。

如果要仅将更改应用于当前文件

选项1:您可以在导航栏中选择:编辑->转换缩进->转换为空格。(见下图)

在此处输入图片说明

选项2:您可以通过在macOS或Windows / Linux 上运行“ 查找操作”快捷方式来执行“到空间”操作。然后键入“ To Spaces”,然后如下图所示运行操作。ActrlA

在此处输入图片说明

PyCharm 2019.1

If you want to change the general settings:

Open preferences, in macOS ; or in Windows/Linux Ctrl + Alt + S.

Go to Editor -> Code Style -> Python, and if you want to follow PEP-8, choose Tab size: 4, Indent: 4, and Continuation indent: 8 as shown below:

enter image description here

Apply the changes, and click on OK.

If you want to apply the changes just to the current file

Option 1: You can choose in the navigation bar: Edit -> Convert Indent -> To Spaces. (see image below)

enter image description here

Option 2: You can execute “To Spaces” action by running the Find Action shortcut: A on macOS or ctrlA on Windows/Linux. Then type “To Spaces”, and run the action as shown in the image below.

enter image description here


回答 5

ctr + alt + shift + L->重新格式化整个文件:)

ctr+alt+shift+L -> reformat whole file :)


回答 6

对我来说,它有一个名为〜/ .editorconfig的文件,它将覆盖我的标签设置。我删除了它(肯定有一天会再次咬我),但是它解决了我的pycharm问题

For me it was having a file called ~/.editorconfig that was overriding my tab settings. I removed that (surely that will bite me again someday) but it fixed my pycharm issue


声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。