You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Visual Studio provides an interactive read-evaluate-print loop (REPL) window for each of your Python environments, which improves upon the REPL you get with *python.exe* on the command line. The **Interactive** window (opened with the **View** > **Other Windows** > **<environment> Interactive** menu commands) lets you enter arbitrary Python code and see immediate results. This way of coding helps you learn and experiment with APIs and libraries and interactively develop working code to include in your projects.
20
+
Visual Studio provides an interactive read-evaluate-print loop (REPL) window for each of your Python environments, which improves upon the REPL you get with _python.exe_ on the command line. The **Interactive** window (opened with the **View** > **Other Windows** > **<environment> Interactive** menu commands) lets you enter arbitrary Python code and see immediate results. This way of coding helps you learn and experiment with APIs and libraries and interactively develop working code to include in your projects.
| Standard | Default REPL talks to Python directly | Standard editing (multiline, and so on). | Yes, via `$attach`| No|
29
+
| Debug | Default REPL talks to debugged Python process | Standard editing | Only debugging | No|
30
+
| IPython | REPL talks to IPython backend | IPython commands, Pylab conveniences | No | Yes, inline in REPL|
31
+
| IPython w/o Pylab | REPL talks to IPython backend | Standard IPython | No| Yes, separate window |
31
32
32
33
This article describes the **Standard** and **Debug** REPL modes. For details on IPython modes, see [Use the IPython REPL](interactive-repl-ipython.md).
33
34
@@ -65,20 +66,20 @@ Once the **Interactive** window is open, you can start entering code line-by-lin
65
66
66
67
The exception is when more lines of code are needed to make a complete statement, such as when a `for` statement ends in a colon as shown above. In these cases, the line prompt changes to **...**, indicating that you need to enter more lines for the block, as shown on the fourth and fifth lines in the graphic above. When you press **Enter** on a blank line, the **Interactive** window closes the block and runs it in the interpreter.
67
68
68
-
> [!Tip]
69
-
> The **Interactive** window improves upon the usual Python command-line REPL experience by automatically indenting statements that belong to a surrounding scope. Its history (recalled with the up arrow) also provides multiline items, whereas the command-line REPL provides only single lines.
70
-
<a name="meta-commands"></a>
71
-
The **Interactive** window also supports several meta-commands. All meta-commands start with `$`, and you can type `$help` to get a list of the meta-commands and `$help <command>` to get usage details for a specific command.
69
+
> [!Tip]
70
+
> The **Interactive** window improves upon the usual Python command-line REPL experience by automatically indenting statements that belong to a surrounding scope. Its history (recalled with the up arrow) also provides multiline items, whereas the command-line REPL provides only single lines.
71
+
> <aname="meta-commands"></a>
72
+
> The **Interactive** window also supports several meta-commands. All meta-commands start with `$`, and you can type `$help` to get a list of the meta-commands and `$help <command>` to get usage details for a specific command.
72
73
73
-
| Meta-command | Description |
74
-
| --- | --- |
75
-
|`$$`| Inserts a comment, which is helpful to comment code throughout your session. |
|`$$`| Inserts a comment, which is helpful to comment code throughout your session.|
76
77
|`$cls`, `$clear`| Clears the contents of the editor window, leaving history and execution context intact. |
77
-
|`$help`| Display a list of commands, or help on a specific command. |
78
-
|`$load`| Loads commands from file and executes until complete. |
79
-
|`$mod`| Switches the current scope to the specified module name. |
80
-
|`$reset`| Resets the execution environment to the initial state, but keeps history. |
81
-
|`$wait`| Waits for at least the specified number of milliseconds. |
78
+
|`$help`| Display a list of commands, or help on a specific command.|
79
+
|`$load`| Loads commands from file and executes until complete.|
80
+
|`$mod`| Switches the current scope to the specified module name.|
81
+
|`$reset`| Resets the execution environment to the initial state, but keeps history.|
82
+
|`$wait`| Waits for at least the specified number of milliseconds.|
82
83
83
84
Commands are also extensible by Visual Studio extensions by implementing and exporting `IInteractiveWindowCommand` ([example](https://github.com/Microsoft/PTVS/blob/master/Python/Product/PythonTools/PythonTools/Repl/InteractiveWindowCommands.cs#L85)).
84
85
@@ -103,10 +104,11 @@ In addition to working within the **Interactive** window directly, you can selec
103
104
104
105
This command is useful for iterative or evolutionary code development, including testing your code as you develop it. For example, once you've sent a piece of code to the **Interactive** window and seen its output, you can press the up arrow to show the code again, modify it, and test it quickly by pressing **Ctrl**+**Enter**. (Pressing **Enter** at the end of input executes it, but pressing **Enter** in the middle of input inserts a newline.) Once you have the code you want, you can easily copy it back into your project file.
105
106
106
-
> [!Tip]
107
-
> By default, Visual Studio removes **>>>** and **...** REPL prompts when pasting code from the **Interactive** window into the editor. You can change this behavior on the **Tools** > **Options** > **Text Editor** > **Python** > **Advanced** tab using the **Paste removes REPL prompts** option. See [Options - Miscellaneous options](python-support-options-and-settings-in-visual-studio.md#miscellaneous-options).
107
+
> [!Tip]
108
+
> By default, Visual Studio removes **>>>** and **...** REPL prompts when pasting code from the **Interactive** window into the editor. You can change this behavior on the **Tools** > **Options** > **Text Editor** > **Python** > **Advanced** tab using the **Paste removes REPL prompts** option. See [Options - Miscellaneous options](python-support-options-and-settings-in-visual-studio.md#miscellaneous-options).
108
109
109
110
<!-- After 15.3 is released, you can also press **Undo** after pasting to restore prompts. Press **Undo** a second time to remove the pasted code entirely. -->
111
+
110
112
:::moniker-end
111
113
112
114
:::moniker range=">=vs-2022"
@@ -116,21 +118,12 @@ In addition to working within the **Interactive** window directly, you can selec
116
118
117
119
This command is useful for iterative or evolutionary code development, including testing your code as you develop it. For example, once you've sent a piece of code to the **Interactive** window and seen its output, you can press the up arrow to show the code again, modify it, and test it quickly by pressing **Ctrl**+**E**. (Pressing **Enter** at the end of input executes it, but pressing **Enter** in the middle of input inserts a newline.) Once you have the code you want, you can easily copy it back into your project file.
118
120
119
-
> [!Tip]
120
-
> By default, Visual Studio removes **>>>** and **...** REPL prompts when pasting code from the **Interactive** window into the editor. You can change this behavior on the **Tools** > **Options** > **Text Editor** > **Python** > **Advanced** tab using the **Paste removes REPL prompts** option. See [Options - Miscellaneous options](python-support-options-and-settings-in-visual-studio.md#miscellaneous-options).
121
+
> [!Tip]
122
+
> By default, Visual Studio removes **>>>** and **...** REPL prompts when pasting code from the **Interactive** window into the editor. You can change this behavior on the **Tools** > **Options** > **Text Editor** > **Python** > **Advanced** tab using the **Paste removes REPL prompts** option. See [Options - Miscellaneous options](python-support-options-and-settings-in-visual-studio.md#miscellaneous-options).
121
123
122
124
<!-- After 15.3 is released, you can also press **Undo** after pasting to restore prompts. Press **Undo** a second time to remove the pasted code entirely. -->
123
-
:::moniker-end
124
-
125
-
## Work with code cells
126
125
127
-
Code cells can be used in data analysis and are supported by various text editors.
128
-
129
-
For example, when using a code file as a scratchpad, you often have a small block of code you want to send all at once. To group code together, mark the code as a *code cell* by adding a comment starting with `#%%` to the beginning of the cell, which ends the previous one. Code cells can be collapsed and expanded, and using **Ctrl**+**Enter** inside a code cell sends the entire cell to the **Interactive** window and moves to the next one.
130
-
131
-
Visual Studio also detects code cells starting with comments like `# In[1]:`, which is the format you get when exporting a Jupyter notebook as a Python file. This detection makes it easy to run a notebook from [Azure Notebooks](https://notebooks.azure.com/) by downloading it as a Python file, opening in Visual Studio, and using **Ctrl**+**Enter** to run each cell.
0 commit comments