• [PyCharm IDE]
 

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migrated to Confluence 4.0

...

First run

Off we go. Open the

span
classcode
Wiki Markup
{span:class=code}Solver.py{span}
for editing and right-click the editor background. Then choose Run
span
classshortcut
Wiki Markup
{span:class=shortcut}Run 'Solver'{span}
on the context menu:

The script runs and shows output in the Run tool window:

...

Excerpt

Each script or test you wish to run or debug from within PyCharm, needs a special profile that specifies script name, working directory, and other important data required for running or debugging. PyCharm comes with a number of such pre-defined profiles, or run/debug configurations that serve patterns, against which you can create any number of run/debug configurations of your own.

Every time you click the Run or Debug buttons (or choose Run or Debug commands on the context menu), you actually launch the current run/debug configuration in the run or debug mode.


If you look at the very first image, you will notice that in the combobox there is no run/debug configuration at all; on the second image it appears. It means that the Solver run/debug configuration has been created automatically by PyCharm, when you've chosen Run
span
classshortcut
Wiki Markup
{span:class=shortcut}Run 'Solver'{span}
on the context menu. Now, as this run/debug configuration is shown in the combobox, it is current.

...

This command is first in the list. Choose 

Edit configuration
span
classshortcut
Wiki Markup
{span:class=shortcut}Edit configuration{span}
, and see the Run/Debug Configurations dialog box open:

...

You've already executed the Solver script in one of the most staright-forward ways. Let us now explore the other ways to run a script.

...

  • Click the Run button , located next to the run/debug configuration combobox.
  • Press 
    span
    classshortcut
    Wiki Markup
    {span:class=shortcut}Shift+F10{span}
  • On the main menu, choose Run → Run
    span
    classshortcut
    Wiki Markup
    {span:class=shortcut}Run → Run{span}

Now you can observe results in the Run tool window.

...

To run a test, you have to create it first. PyCharm suggests a smart way to stub out a test: click the class name and then press 

span
classshortcut
Wiki Markup
{span:class=shortcut}Ctrl+Shift+T{span}
, or on the main menu, choose Navigate → Test
span
classshortcut
Wiki Markup
{span:class=shortcut}Navigate → Test{span}
. If a test exists, you can jump directly to it; if it doesn't - PyCharm will create it:

...

OK, we've paused at the first breakpoint. The Frames area shows the first thread

demo
span
classcode
Wiki Markup
{span:class=code}demo{span}
in the 7th line of the script Solver
span
classcode
Wiki Markup
{span:class=code}Solver{span}
; the corresponding variables
span
classcode
Wiki Markup
{span:class=code}a,b,c{span}
are already defined, but the variable d
span
classcode
Wiki Markup
{span:class=code}d{span}
is not. What's next?

Press

F9
span
classshortcut
Wiki Markup
{span:class=shortcut}F9{span}
(or click in the toolbox to the left) - the programm will resume and pause at the next breakpoint. This way you can step through all the set breakpoints, observing the variables used in the application.

For more information about working with frames, watches, evaluating expressions etc. refer to the product documentation and to the

Wiki Markup
{link-page
linkTextDebugger tutorial
namePYH:Debugger
:name=Debugger}Debugger tutorial{link-page}
.

Working in the Console tab

...

Note that interactive console provides code completion (

span
classshortcut
Wiki Markup
{span:class=shortcut}Ctrl+Space{span}
) and history (
span
classshortcut
Wiki Markup
{span:class=shortcut}Up/Down{span}
arrow keys). Refer to the page Using Debug Console for more information.

...

Finally, if you are used to working with an interactive console, you can also do that right from within PyCharm. To launch the console, choose

Tools → Run Python
span
classshortcut
Wiki Markup
{span:class=shortcut}Tools → Run Python Console...{span}
on the main menu:

The interactive Python console runs in a separate tab of the Run tool window:

...

In this console, you can also do a lot of interesting things: enjoy code completion, history, executing each current statement etc.. Here we'll see how our ever-lasting

span
classcode
Wiki Markup
{span:class=code}Solver.py{span}
will work from within the Python console.

Open

span
classcode
Wiki Markup
{span:class=code}Solver.py{span}
in the editor (there're many ways to do it... as an exercise, try
span
classshortcut
Wiki Markup
{span:class=shortcut}Ctrl+E{span}
- View → Recent Files
span
classshortcut
Wiki Markup
{span:class=shortcut}View → Recent Files{span}
). Then select all contents of the
span
classcode
Wiki Markup
{span:class=code}Solver.py{span}
file (
span
classshortcut
Wiki Markup
{span:class=shortcut}Ctrl+A{span}
, or Edit → Select All
span
classshortcut
Wiki Markup
{span:class=shortcut}Edit → Select All{span}
), and press
span
classshortcut
Wiki Markup
{span:class=shortcut}Alt+Shift+E{span}
(or on the context menu choose Execute Selection in Console
span
classshortcut
Wiki Markup
{span:class=shortcut}Execute Selection in Console{span}
):

Lo and behold! PyCharm has loaded the selected code in the Python console and executed it!

...