简体   繁体   English

Notepad ++缩进搞砸了

[英]Notepad++ indentation messes up

I'm coding in Python and I really like Notepad++. 我用Python编写代码,我非常喜欢Notepad ++。 However, off late when I use tab to indent, it seems fine in Notepad++, but when I run the program I get an indentation error, and when I check my code in Emacs or something, I find that Notepad++ actually adds more tab spaces than it shows on screen. 但是,当我使用tab缩进时,在Notepad ++中似乎很好,但是当我运行程序时,我得到一个缩进错误,当我在Emacs中检查我的代码时,我发现Notepad ++实际上添加的选项卡空间比它显示在屏幕上。 What is happening? 怎么了?

There is no universal tab size, so I always make sure to replace tabs by spaces (so you know what you see is what you get everywhere else as well) 没有通用的标签大小,所以我总是确保用空格替换标签(所以你知道你看到的是你在其他地方得到的)

Go to Settings -> "Preferences..." -> Language Menu/Tab Settings and check 'Replace by space' 转到设置 - >“首选项...” - >语言菜单/选项卡设置,然后选中“按空格替换”

我建议您去查看>显示符号>显示空白和标签,以更好地了解缩进的外观。

PEP 8 tells us to use spaces instead of tabs in Python for cross-editor compatibility and consistency: PEP 8告诉我们在Python中使用空格而不是制表符来实现交叉编辑器的兼容性和一致性:

http://www.python.org/dev/peps/pep-0008/ http://www.python.org/dev/peps/pep-0008/

Have a look at this answer for how to change tabs to spaces in Notepad++ 看看如何在Notepad ++中将标签更改为空格的答案

Convert tabs to spaces in Notepad++ 在Notepad ++中将制表符转换为空格

Perhaps that will fix your problem 也许那会解决你的问题

微小更新 - 要将空格作为选项卡,现在转到设置>>首选项>>标签设置并选中“按空格替换”框

I am new to python and started using Notepad++. 我是python的新手并开始使用Notepad ++。 But I faced the same issue as you... Indentation problems. 但是我遇到了和你一样的问题......压痕问题。 On my senior's advice, I switched to PyCharm community edition. 根据我老人的建议,我改用了PyCharm社区版。 I pasted the code from Notepad++ to PyCharm and it highlighted the block with indentation problems... The issue was that, some of the lines used spaces and some used tabs. 我将代码从Notepad ++粘贴到PyCharm,它突出显示了带缩进问题的块...问题是,有些行使用了空格,有些使用了制表符。 This happened because the code on which I was working was taken from the internet. 发生这种情况是因为我工作的代码是从互联网上获取的。

Checking for such inconsistencies would solve the problem. 检查这种不一致性可以解决问题。 Or, there is a better alternative... Switch to PyCharm. 或者,有一个更好的选择......切换到PyCharm。 It is exclusively built for python coding.. Hope this helps people like me searching for solutions for indentation issues in Notepad++ 它专为python编码而构建。希望这有助于像我这样的人在Notepad ++中搜索缩进问题的解决方案

Use Python Indent Plugin for Notepad++: I have used both Pycharm & Notepad++, and frankly - even though both are installed on my machine right now I prefer using Notepad++. 使用用于Notepad ++的Python Indent Plugin:我已经使用了Pycharm和Notepad ++,坦率地说 - 即使两者都安装在我的机器上,我现在更喜欢使用Notepad ++。 So, if you want to continue using Notepad++ for Python development you should definitely install the 'Python Indent' Plugin. 所以,如果你想继续使用Notepad ++进行Python开发,你一定要安装'Python Indent'插件。 This plugin will automatically create tabs for you when writing Python code. 在编写Python代码时,此插件将自动为您创建选项卡。 The only downside to the plugin is you have to remember to Enable it (by going to Plugins --> Python Indent and then clicking 'Enable') when you want to use it. 插件的唯一缺点是你必须记住启用它(通过转到插件 - > Python缩进,然后单击'启用')当你想要使用它。

To install the Python Indent plugin in Notepad++ just go to 'Plugins' --> 'Plugin Manager' and then click on 'Show Plugin Manager'. 要在Notepad ++中安装Python Indent插件,只需转到“插件” - >“插件管理器”,然后单击“显示插件管理器”。 Then check off 'Python Indent' and click on the 'Install' button. 然后选中'Python Indent'并单击'Install'按钮。

Additionally, you should Follow Python's Usage Guide: Tab spacing can differ across programs and, following the recommendations of PEP8 (Python Enhancement Proposals Number 8 - which is Python's Accepted Styling and Usage Guide) you should use the space bar to make your indents. 此外,您应该遵循Python的使用指南:选项卡间距可能因程序而异,并且遵循PEP8(Python增强建议编号8 - Python的“接受的样式和使用指南”)的建议,您应该使用空格键进行缩进。 Check out the PEP8 Page about spacing here: https://www.python.org/dev/peps/pep-0008/#tabs-or-spaces 在这里查看关于间距的PEP8页面: https ://www.python.org/dev/peps/pep-0008/#tabs-or-spaces

Good luck! 祝好运!

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

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