

When you manually enter the code, it can run correctly regardless of whether the code contains an unpack operator, but when the code contains an unpack operator, copy and paste the code and then run it will cause an error. You can try to create a new project to run this code.Īccording to your statement, I read this document and tested it, and I found this result: I successfully ran your code in Visual Studio 2017, whether it is four spaces or a Tab, it runs successfully. Does anyone know what's causing the unexpected indent error in the VS Python interactive window? Thanks for any info! vs-general To top it off, when the code with the unpack operator is executed in a windows command prompt, it works perfectly! I.e., save the python snippet as TestUnpack.py, then type "py -m TestUnpack" in a windows command prompt. I've tried None, Block, and Smart for indenting options, and both Insert Spaces and Keep Tabs for tab options, nothing fixes the error. This results in the following output: j = 0Īll the indents are consistent, either 4 blank spaces or a tab of length 4.

The code differs from the above only in the insertion of an asterisk before mylist in the print statement: Then I decided I wanted the output of mylist to be just a list of space-separated integers (no commas or brackets), by using the unpack operator (*). First I'll show the code that works as expected: There are three main cases when determining the correct indentation, described below.I'm trying to execute a short snippet of python code in the VS 2017 Python Interactive Window. Theme used in gif: Community Theme Palenight from Community Material Theme v1.4.4.Įvery time you press the Enter key in a Python context, this extension will parse your Python file up to the location of your cursor, and determine exactly how much the next line (or two in the case of hanging indents) should be indented and how much nearby lines should be un-indented. See the extension on the VSCode Marketplace and its source code on GitHub. Correct Python indentation in Visual Studio Code.
