Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spyder IDE automatic indentation

Tags:

python

spyder

Is there any shortcut to automatically indent marked lines in the editor? For example, in MATLAB there is the CTRL+I shortcut.

like image 267
mat Avatar asked Dec 03 '22 14:12

mat


2 Answers

Matlab's syntax can match the opening closing statements of if,while, for etc. by looking for end statements.

In Python these are ambiguous and defined as the nested indentetation. Hence this cannot be reliably implemented as you cannot decide whether the succeeding if block belongs the the current for loop or it is the next block, if not indented properly.

If indented properly then Forzaa's answer is the answer otherwise the code is useless anyway and needs to be debugged.

like image 122
percusse Avatar answered Dec 19 '22 05:12

percusse


First I will just reconfirm what has been said above, that python is ambiguous about what should be the correct indent. Unfortunately as coming from Matlab I also like Ctrl-I.

Though just check on how Tab and Shift-Tab work in practice, they did a little better than I expected. When I ended up having 2 tabs too much after rearranging code, one Shift-tab brought it back to proper position.

like image 20
Sven Hartjenstein Avatar answered Dec 19 '22 06:12

Sven Hartjenstein