I’m on python, VS Code, Mac. When trying to indent multiple lines by selecting them and pressing ‘tab’, the blank lines are not indented, resulting in "IndentationError" from python. (In the picture below, you can see that the three dots are missing at the blank line, indicating that indenting multiple lines did not work for the blank line. How do I indent multiple lines without causing an IndentationError?
Question posted in Visual Studio Code
View the official documentation.
View the official documentation.
2
Answers
VS Code, like most other Python editors, is for editing Python files rather than for preparing things for pasting into an interactive session.
When the Python process executes a .py file it does not regard blank lines as ending indents, that is only a feature of the interactive mode so it can know when to execute the indented block.
More information about the difference between handling blank lines in interactive and scripts can be found in this question: Blank line rule at interactive prompt
Just don’t use blank lines in your functions if you want to use them in an interactive prompt.
Are your vscode and Python extensions the latest version? This is not the case in the latest version.
This may also be related to the way you operate