indent python file (with pydev) in eclipse indent python file (with pydev) in eclipse python python

indent python file (with pydev) in eclipse


If you want to change from 2 space to 4 space indentation (for instance), use "Source->Convert space to tab" with 2 spaces, then "Soruce->Convert tab to space" with 4 spaces.


I ... don't think this question makes sense. Indentation is syntax in Python. It doesn't make sense to have your IDE auto-indent your code. If it's not indented properly already, it doesn't work, and the IDE can't know where your indentation blocks begin and end. Take, for example:

# Valid Codefor i in range(10):  b = ifor j in range(b):  c = j# Also Valid Code.for i in range(10):  b = i  for j in range(b):    c = j

There's no possible way that the IDE can know which of those is the correct version, or what your intent is. If you're going to write Python code, you're going to have to learn to manage the indentation. There's no way to avoid it, and expecting the IDE to magically clean it up and still get the desired result out of it is pretty much impossible.

Further example:

# Valid Code.outputData = []for i in range(100):  outputData.append(str(i))print ''.join(outputData)# Again, also valid code, wildly different behavior.outputData = []for i in range(100):  outputData.append(str(i))  print ''.join(outputData)

The first will produce a list of strings, then print the joined result to the console 1 time. The second will still produce a list of strings, but prints the cumulative joined result for each iteration of the loop - 100 print statements. The two are both 100% syntactically correct. There's no problem with them. Either of them could be what the developer wanted. An IDE can't "know" which is correct. It could, very easily incorrectly change the first version to the second version. Because the Language uses Indentation as Syntax, there is no way to configure an IDE to perform this kind of formatting for you.


Although auto-indentation is not a feature of PyDev because of the language design you should be able to indent with a simple tab. Just select the lines you want to indent and press Tab. If you want to unindent lines you have to press Shift+Tab.Thats all.