Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Follow these steps to open an existing script:

  • Click Open file from the file menu and locate your file by browsing your disk or

  • Double click the Python script in the Project Explorer.

  • Make sure that your

    projet’s

    project’s file system is visible by clicking the Filter resources button in the Project Explorer view.

  • Expand your project in the Project Explorer view and locate the Python script in the file system.

  • Double click the Python script.

  • Drag and drop a Python script from the Windows Explorer to the RT-LAB editor area.

Editing a script

The script editor has a rich set of functionalities that let you edit your script easily. Here
is a brief description of the available features:

Syntax highlighting

Provide different colors and text styles to be given to dozens of different


lexical sub-elements of the Python syntax. These include keywords, comments, control-flow


statements, variables, and other elements. Programmers often heavily customize their settings in


an attempt to show as much useful information as possible without making the code difficult to


read.

Code analysis

Provides error finding in python programs. It finds common errors such as


undefined tokens, duplicated signatures and warns about things such as unused variables or


unused imports.

Code completion

provides context-sensitive completions and is enabled with Ctrl+Space key in


the editor.

Refactoring

Provides functionalities to change the source code to improve code readability, reduce


complexity and improve the maintainability of the source code such as renaming, extracting,


inlining code elements.

Navigation Views

Outline View, Hierarchy View, ...

Content Assistants

Helps user to write code faster and more efficiently by providing list of


accessible keywords such as variable, method, import, module, ...

Once your script is open in the editor, perform the following steps to edit your script:

  • Locate the part of your script you want to edit.

  • Type your text.

  • Save your file by clicking the Save button in the main toolbar.

Running a script

Follow these steps to run a script:

  • Select the Python script from the Project Explorer or click inside your script in the editor area.

  • On the Tools > Python menu, click Run item (Ctrl-F11), or simply click the Run item in the drop-down menu of the Python toolbar.

Debugging a script

Follow these steps to debug a script:

Open the Python script. See Opening a script for more information.

  • Add breakpoint to your script:

  • Double-click the script’s left ruler or

  • Type Ctrl+F10 to open the context menu. If everything goes ok, you'll have the breakpoint shown in your sidebar (as below).

...

Right-click the file and choose to debug the file as a python run.

#D3D3D3
Background Color
color
Info

Note: if you want to re-run the last executed file, you can click F11 to debug it.

When it hits the break-point, it will ask you to go to the debug perspective (click YES to this dialog).

This perspective has the actions needed for debugging and allows you to see the variables and evaluate expressions.Image Removed

...

Stack view

You can see the variables in previous stacks by clicking on the stack to view.

Variables view

Allows you to see the globals and locals for the selected stack.

Breakpoints view

Allows you to see the breakpoints available and enable/disable any breakpoint.

Editor

Shows the code and highlights the line to be executed.

Console

Shows the output of the Python script.

The basic things you can do in the debugger have some keybindingskey bindings:

Step in

F5

Step over

F6

Step out

F7

Resume

F8

Migrating scripts from Python 2 to Python 3

As of RT-LAB version 2023.2, the python interpreter internally used by RT-LAB on the host computer has been upgraded from Python 2.7 to Python 3.9.  The core of the Python syntax language remains the same, but the language has nonetheless evolved and corrections might be required to make Python scripts compatible with Python 3.9.  To help with the conversion of scripts, the Python community provides a very helpful tool, 2to3 that is included with the Python distribution.

Please note that the following caveats have been observed with the 2to3 tool:

  • scripts containing non-standard English characters (such é,ö, etc.) will make the 2to3 tool fail, even if they are only part of comments

  • not all the changes suggested by the 2to3 tool are essential for the scripts to be operational in Python 3.9.  Some of the changes proposed are more of a recommended programming, but the old Python 2 syntax remains valid. The user remains responsible for using his own judgement.