Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Tab not working properly in Python

I have been using NotePAD++ for editing Python scripts. I recently downloaded the PyDEV IDE (for Eclipse). The problem is that when I wrote the scripts in NotePad++ I used "TAB" for indentation, and now when I open them with PyDEV, every time I try to write a new line instead of "TABS" PyDEV inserts spaces. (even if I click the "TAB" key Eclipse inserts 4 spaces instead of one tab). This raises indentation error.

Is there anyway to fix this thing?

Thanks!

like image 266
Joel Avatar asked Oct 11 '25 20:10

Joel


2 Answers

Yes, follow http://www.python.org/dev/peps/pep-0008/ which states:

Indentation

Use 4 spaces per indentation level.

Replace all your tabs with spaces, and set Notepad++ to use spaces instead of tabs.

Setting Eclipse to use tabs instead of spaces would be a step in the wrong direction.

like image 99
mthurlin Avatar answered Oct 14 '25 10:10

mthurlin


Tabs are problematic—different people can choose different widths in their editor settings, and then you have bad formatting (for e.g. C) or execution problems (Python). So spaces are better for getting consistently sensible results. But one issue with that is that some editors still default to using tabs.

In the companies I've worked for, our coding guidelines have specified that we should always use spaces, no tabs. But default editor settings sometimes catch us out.

In Eclipse with PyDev, the fast way to convert tabs to spaces is the menu item Source⇒Convert tabs to space-tabs.

like image 28
Craig McQueen Avatar answered Oct 14 '25 10:10

Craig McQueen