Bug fixes in Python

Bug fixes in Python

Product line

Standard

|

Expert

Operating mode

CLOUD ABO

|

ON-PREMISES

Modules

Services & CRM

Budget & Phases

Purchases

Resource Planning

Business Intelligence

Created: 22.02.2010
Updated: 21.11.2022 | begin/endsystemcontext() replaced by vtcapp.systemcontext().

If a script does not run and an error message is returned, you can analyze it in more detail as follows.

  • Open the script in the Script Editor and click execute, making sure that the argobject is of the correct type, e.g. a service or a project. The script will execute and the error message will appear in the output on the right:
  • Alternatively, on the object where the error occurs, you can open the Python console and execute the script again. The error message will then appear in the console:

In the error message you will find the line number on which the problem occurs, for example:

Traceback (most recent call last):
File “<string>,” line 146, in <module>
File “<string>,” line 85, in main
NameError: global name 'showPiority’ Inf not defined

It is always the lowest line number relevant to the current error, so here it occurs in row 85 of the script.

The script can now navigate to this row. The error is now clear: showPiority is a typo and should be called showPriority.

Correct errors, save, and execute the script again.

Common sources of error

Use of variables

When using variables, you must be case sensitive. Python is case sensitive. When using variables, you must always keep in mind that the variable matches 1:1.

var1 is not equal to var1

In such cases, it is rather difficult to find the error because in certain cases, Python does not output an error, but instead creates a new variable 'Var1'. Therefore, always make sure that the variable used is named exactly.

Indentation

The Python interpreter handles an indent correctly if it contains 4 spaces. A tab is automatically replaced by 4 spaces in a Python editor.

If a piece of code is copied from a web page or other text file into the Python Editor, care must be taken that it does not have tab indents. If this is the case, the tabs must be replaced by 4 spaces. Several editors support the option Replace tab with x characters.

Collection types (list, dictionaries, dictionary)

Collection types should be created before use as a precaution to avoid unexpected errors (accessing or returning non-existent lists, etc.)

  • Create list: list = []
  • Create dictionary: dict = {}

System context not allowed

This error occurs when you access the system context, but it is not allowed. For example, for security reasons, it is not allowed to execute Python scripts with vtcapp.Systemcontext() directly in the Python Editor, as this operation grants accepted user rights, which requires a corresponding login. See also the description in the Vertec Python Functions .

Bitte wählen Sie Ihren Standort