- #PYTHON WINDOW CODERUNNER FOR MAC#
- #PYTHON WINDOW CODERUNNER CODE#
- #PYTHON WINDOW CODERUNNER WINDOWS#
#PYTHON WINDOW CODERUNNER CODE#
Visual Studio also detects code cells starting with comments like # In:, which is the format you get when exporting a Jupyter notebook as a Python file. 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. 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. Work with code cellsĬode cells can be used in data analysis and are supported by various text editors.įor example, when using a code file as a scratchpad, you often have a small block of code you want to send all at once. You can change this behavior on the Tools > Options > Text Editor > Python > Advanced tab using the Paste removes REPL prompts option. REPL prompts when pasting code from the Interactive window into the editor. For example, using import importlib followed by dir() shows the following message:īy default, Visual Studio removes > and. A message in the Interactive window also indicates the new scope, so you can track how you got to a certain state during your session.Įntering dir() in a scope displays valid identifiers in that scope, including function names, classes, and variables. Once you import a module, such as typing import importlib, options appear in the drop-down to switch into any scope in that module. At any time during your REPL session, however, the drop-down menu along the top of the Interactive window lets you change the scope: For a stand-alone file, it scopes to that file. Switch scopesīy default, the Interactive window for a project is scoped to the project's startup file as if you ran it from the command prompt. Waits for at least the specified number of milliseconds.Ĭommands are also extensible by Visual Studio extensions by implementing and exporting IInteractiveWindowCommand ( example). Resets the execution environment to the initial state, but keeps history. Switches the current scope to the specified module name. Loads commands from file and executes until complete. Inserts a comment, which is helpful to comment code throughout your session.Ĭlears the contents of the editor window, leaving history and execution context intact.ĭisplay a list of commands, or help on a specific command. When you press Enter on a blank line, the Interactive window closes the block and runs it in the interpreter. , indicating that you need to enter more lines for the block, as shown on the fourth and fifth lines in the graphic above. In these cases, the line prompt changes to. 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. The Interactive window executes each line as you enter it, which includes options such as importing modules, defining variables. Once the Interactive window is open, you can start entering code line-by-line at the > prompt.
#PYTHON WINDOW CODERUNNER WINDOWS#
You can control various aspects of the Interactive window through Tools > Options > Python > Interactive Windows (see Options): Third, you can open an Interactive window for the startup file in your project, or for any stand-alone file, by selecting the Debug > Execute in Python Interactive menu command ( Shift+ Alt+ F5):įinally, you can select code in file and use the Send to Interactive command described in the following section. Second, near the bottom of the View > Other Windows menu, there's a Python Interactive Window command for your default environment, and a command to switch to the Environments window: There are several ways to open the Interactive window for an environment.įirst, switch to the Python Environments window ( View > Other Windows > Python Environments or Ctrl+ K > Ctrl+ `) and select the Open Interactive Window command or button for a chosen environment. For details on IPython modes, see Use the IPython REPL.įor a detailed walkthrough with examples, including the interactions with the editor such as Ctrl+ Enter, see Tutorial Step 3: Use the Interactive REPL window. This article describes the Standard and Debug REPL modes. Visual Studio has many Python REPL modes to choose from: REPLĭefault REPL talks to debugged Python process This way of coding helps you learn and experiment with APIs and libraries and interactively develop working code to include in your projects. The Interactive window (opened with the View > Other Windows > Interactive menu commands) lets you enter arbitrary Python code and see immediate results.
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.
#PYTHON WINDOW CODERUNNER FOR MAC#
Applies to: Visual Studio Visual Studio for Mac Visual Studio Code